Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved MissingReferenceException when running integration test

Discussion in 'Testing & Automation' started by hepphep, Nov 7, 2017.

  1. hepphep


    Feb 1, 2013
    I've run into bit of strange issue, that doesn't give me that much of useful detail, but seems more like it has something to do with integration test runner itself.

    When running integration test in on scene, I get following error

    MissingReferenceException: The object of type 'Sprite' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Sprite.get_border () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/SpritesBindings.gen.cs:210)
    UnityEngine.UI.Image.get_hasBorder () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Image.cs:163)
    UnityEngine.UI.Image.GenerateSlicedSprite (UnityEngine.UI.VertexHelper toFill) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Image.cs:360)
    UnityEngine.UI.Image.OnPopulateMesh (UnityEngine.UI.VertexHelper toFill) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Image.cs:297)
    UnityEngine.UI.Graphic.DoMeshGeneration () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:380)
    UnityEngine.UI.Graphic.UpdateGeometry () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:374)
    UnityEngine.UI.Graphic.Rebuild (UnityEngine.UI.CanvasUpdate update) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:335)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:150)

    That comes immediately at the start and keeps on coming continuously until the test runner decides that test has failed.

    The scene runs all nicely and without any errors if I run it just clicking play and playing around. Also, with exactly same version of source code and others, I managed to run the same test yesterday without any errors (even though it was already giving same failure to our other programmer back then already).

    Anyone else has run into same issue or could give me some insights where I should dig more deep, as the stack trace does not give real indication that it would be some specific thing in our code itself?

    Unity version is 2017.1.1p2
  2. hepphep


    Feb 1, 2013
    And as usual, immediately after posting question the issue is found in our own code. The issue actually was that our test data was serialized recording of earlier play session. In this recording we also serialized one object with preference to sprite prefab for icon to be shown. As part of serialization, it was saved as instanceId for that prefab which apparently changes when you restart Unity editor and therefore could not be found anymore when deserializing. Getting rid of that reference solved the issue for us. Could've been useful to get some better notification of that deserialization issue though.