Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

IDToPointer assert on async levelload

Discussion in 'Editor & General Support' started by supmagc, Apr 11, 2013.

  1. supmagc

    supmagc

    Joined:
    Feb 25, 2010
    Posts:
    5
    Hi,

    I have in my project (unity 4.1.0) a couple of scenes
    - Init (which load Menu asynchronously)
    - Menu
    - Other scenes

    When I play the Menu-scene in editor, everything works fine, however when I load the scene asynchronous from Init, I get the following error: (no back-trace)
    Code (csharp):
    1. ms_IDToPointer->find (obj->GetInstanceID ()) == ms_IDToPointer->end ()
    This error does not show when I load the Menu-scene asynchronously from one of the other scenes.

    I don't recall when I first saw the problem, but at first I didn't really payed any attention to it, since everything seemed to work just fine.
    But as it turns out, everything is not okay, this issue breaks the iPad build.

    I was able to pinpoint the script that causes the problem. It's used to automatically generate a quad with the correct aspect ratio for a given texture to be used as button. (kinda like GUITexture)
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MeshButton : MonoBehaviour {
    5.  
    6.     [SerializeField]
    7.     private Texture2D m_oTexture;  
    8.     [SerializeField]
    9.     private MeshRenderer m_oRenderer;
    10.     [SerializeField]
    11.     private MeshFilter m_oFilter;
    12.     [SerializeField]
    13.     private BoxCollider m_oCollider;
    14.    
    15.     public Texture2D Texture {get{return m_oTexture;}}
    16.    
    17.     public void Assure() {
    18.         m_oRenderer = gameObject.GetComponent<MeshRenderer>();
    19.         m_oFilter = gameObject.GetComponent<MeshFilter>();
    20.         m_oCollider = gameObject.GetComponent<BoxCollider>();
    21.        
    22.         // Assure renderer
    23.         if(null == m_oRenderer) {
    24.             m_oRenderer = gameObject.AddComponent<MeshRenderer>();
    25.         }
    26.         m_oRenderer.hideFlags = HideFlags.HideInInspector;
    27.  
    28.         // Assure meshfilter
    29.         if(null == m_oFilter) {
    30.             m_oFilter = gameObject.AddComponent<MeshFilter>();
    31.         }
    32.         m_oFilter.hideFlags = HideFlags.HideInInspector;
    33.        
    34.         // Assure collider
    35.         if(null == m_oCollider) {
    36.             m_oCollider = gameObject.AddComponent<BoxCollider>();
    37.         }
    38.         m_oCollider.hideFlags = 0;
    39.        
    40.         // Assure correct material
    41.         var oMaterial = Application.isPlaying ? m_oRenderer.material : m_oRenderer.sharedMaterial;
    42.         if(null != oMaterial) {
    43.             if(Application.isPlaying) Destroy(oMaterial);
    44.             else DestroyImmediate(oMaterial);
    45.             oMaterial = null;
    46.         }
    47.         if(null == oMaterial) {
    48.             oMaterial = new Material(Shader.Find("Unlit/Transparent"));
    49.             if(Application.isPlaying) m_oRenderer.material = oMaterial;
    50.             else m_oRenderer.sharedMaterial = oMaterial;
    51.         }
    52.         if(Application.isPlaying) m_oRenderer.material.hideFlags = HideFlags.HideInInspector;
    53.         else m_oRenderer.sharedMaterial.hideFlags = HideFlags.HideInInspector;
    54.  
    55.         // Apply texture
    56.         if(Application.isPlaying) m_oRenderer.material.mainTexture = m_oTexture;
    57.         else m_oRenderer.sharedMaterial.mainTexture = m_oTexture;
    58.  
    59.         // Assure old mesh is removed
    60.         var oMesh = Application.isPlaying ? m_oFilter.mesh : m_oFilter.sharedMesh;
    61.         if(Application.isPlaying) Destroy(oMesh);
    62.         else DestroyImmediate(oMesh);
    63.        
    64.         // If valid texture, make mesh
    65.         if(null != m_oTexture) {
    66.            
    67.             // Assure mesh
    68.             float nRatio = (float)Texture.width / (float)Texture.height;
    69.            
    70.             float nRatioX = nRatio > 1f ? 1f : nRatio;
    71.             float nRatioY = nRatio < 1f ? 1f : 1f / nRatio;
    72.            
    73.             m_oCollider.size = new Vector3(nRatioX, nRatioY, 0.25f);
    74.            
    75.             float nMinX = -0.5f * nRatioX;
    76.             float nMinY = -0.5f * nRatioY;
    77.             float nMaxX = 0.5f * nRatioX;
    78.             float nMaxY = 0.5f * nRatioY;
    79.            
    80.             oMesh = new Mesh();
    81.            
    82.             var aVertex = new Vector3[] {
    83.                 new Vector3(nMinX, nMaxY, 0),
    84.                 new Vector3(nMaxX, nMaxY, 0),
    85.                 new Vector3(nMaxX, nMinY, 0),
    86.                 new Vector3(nMinX, nMinY, 0)
    87.             };
    88.            
    89.             var aUv = new Vector2[] {
    90.                 new Vector2(0, 1),
    91.                 new Vector2(1, 1),
    92.                 new Vector2(1, 0),
    93.                 new Vector2(0, 0)
    94.             };
    95.            
    96.             var aIndex = new int[] {
    97.                 0, 1, 3,
    98.                 1, 2, 3
    99.             };
    100.    
    101.             oMesh.vertices = aVertex;
    102.             oMesh.triangles = aIndex;
    103.             oMesh.uv = aUv;
    104.            
    105.             if(Application.isPlaying) m_oFilter.mesh = oMesh;
    106.             else m_oFilter.sharedMesh = oMesh;
    107.         }
    108.     }
    109.    
    110.     public void SetTexture(Texture2D oTexture) {       
    111.         if(m_oTexture != oTexture) {
    112.            
    113.             m_oTexture = oTexture;
    114.        
    115.             Assure();
    116.         }
    117.     }
    118. }
    119.  
    Somebody else has some experience with this sort problem, or a solution perhaps ?
     
  2. supmagc

    supmagc

    Joined:
    Feb 25, 2010
    Posts:
    5
    Don't know why, but switching to Android and switching back fixed it for me!
     
  3. ldaughtry

    ldaughtry

    Joined:
    Oct 30, 2012
    Posts:
    38
    FYI, I also ran into this problem.

    I had built a custom data editor for our game. It used a lot of reflection and serialization. That's the short version anyways.

    The problem ended up being if I had the editor open while the game was running it would throw several to many of these errors when the game would start:
    Code (csharp):
    1. ms_IDToPointer->find (obj->GetInstanceID ()) == ms_IDToPointer->end ()
    I put some early out logic in my data editors OnGUI to not display while the game was running and that took care of the problem.
     
    Last edited: Jul 14, 2015