Simple Dictionary <string, struct> Crash Unity3d

Issue #173 resolved
Lukas Martin
created an issue

Hi Guys im having some issues regarding the serialization of a Dictionary

Here is the Drawer:

public Dictionary<string, imageData> spriteSwitcher = new Dictionary<string, imageData>();

imageData:

public struct imageData
        {
            public Sprite SpriteData;
            public Vector2 size;
            public Vector3 position;
        }

Steps to reproduce: Just, try to add a key in the dictionary via Inspector and Unity Crash and closes without any debug.

Using Unity3d 5.6.2f1 Version (Free), Windows 10 Ultimate 64 bits, Latest OdinInspector build at the moment (1.0.4.1).

OFFTOPIC: Is there a possibility to join the beta testing group? i'd like to help in the improvement of this project :)

Comments (17)

  1. Tor Esa Vestergaard
    • changed status to open

    Hi Lukas,

    I just mailed you a build of the latest beta patch, where this issue should be fixed. Could you please give it a shot, and confirm that it has been fixed? I could not myself reproduce this in our beta.

    And of course, feel free to keep using the beta and reporting in on any other issues you might experience with it!

  2. Lukas Martin reporter

    @Tor Esa Vestergaard Thank you Tor! after importing the beta, had the same issue (Unity crashed) but with the change of

    This:

    public Dictionary<string, imageData> spriteSwitcher = new Dictionary<string, imageData>();
    

    to This:

    [ShowInInspector]
            private Dictionary<string, imageData> spriteSwitcher;
    

    is no longer crashing and, therefore, i can add keys without any issue at all :)

    I don't know if mark this as resolved or not, but right now, i can't reproduce anymore the issue (with that workaround)

  3. Tor Esa Vestergaard

    With ShowInInspector, the values in the dictionary will not be saved. I still can't manage to reproduce the crash. Can you tell me which version of Unity you're in, and which exact sequence of steps you're going through to cause the crash, start to finish?

    Or better yet, make a small demo project that causes the crash, that I can then have a look at. I would very much like to track this bug down before we release the patch.

    Edit: you already mentioned your unity version, sorry. Missed that for a moment! Nevertheless, a detailed set of steps or a demo project to reproduce it with would be lovely.

  4. Tor Esa Vestergaard

    I have today installed your exact version of Unity, 5.6.2f1, and copied your code. After multiple attempts, I'm afraid I've still failed to make it crash or misbehave a single time. I can add keys to the dictionary on plain game objects in a scene. I can make a prefab instance of it and freely add/remove keys on the prefab instance, and on the prefab. I can set the values of the keys to anything, apply, revert - nothing I do makes it crash.

    I'm afraid I'm stumped on this one, unless you can cook up that project, or a reliable set of steps to reproduce it starting in an empty project.

  5. Lukas Martin reporter

    Hi @Tor Esa Vestergaard, im afraid i was unable to reproduce the error, but i can tell you my suppositions:

    is a big project and is managed with GIT. it was working without any problems before a Merge, but after the merge, the dictionary was NULL and unasigned without any key/value in it.

    I think, for some strange reason, Odin shows the object as null, but for unity, it wasn't. So, the crash happens.

    I can send you the crash reports of unity, but i dont think that would help.

  6. Tor Esa Vestergaard

    No, the memory stack dumps that Unity gives on crashing aren't generally very useful - but if the crash ever happens again, it would be very useful if you could go to "C:\Users\<Username>\AppData\Local\Unity\Editor" and send me the log files there - Unity usually prints out a decent stack trace at the very end of those whenever there's a crash.

    We've had one other person report this, and they couldn't reproduce it a while after it'd happened either. It seems, so far, that this is an issue that might be caused by the old Odin patch, but still happens for a while after upgrading to the new patch until it's "fixed", and then goes away after that. Perhaps we'll just have to put it in under known issues, for now - I'll see if I can get the time to work with upgrading some projects though, and see if I can reproduce it that way.

  7. Tor Esa Vestergaard

    That would definitely help! If you could at least send me the editor log files I mentioned just after a crash has happened, so they contain the crash stack trace, that would most likely help point me in the right direction. And of course, if you could take the time to cook down your project to just the bare minimum of code and assets necessary, and tell me what to do to trigger the crash, that would be fantastic. But of course, whether you're willing to do that is entirely up to you.

  8. Tor Esa Vestergaard

    Thank you very much - that was quite illuminating. Here's the extracted crash stack trace:

    0x0000000141077CB6 (Unity) WalkTypeTree

    0x0000000141077ECF (Unity) WalkTypeTree

    0x0000000141077ECF (Unity) WalkTypeTree

    0x0000000141077ECF (Unity) WalkTypeTree

    0x0000000140544975 (Unity) Prefab::GetPropertyModificationsForObject

    0x0000000140544CE0 (Unity) Prefab::GetPropertyModificationsForObject

    0x0000000140544CE0 (Unity) Prefab::GetPropertyModificationsForObject

    0x0000000140544CE0 (Unity) Prefab::GetPropertyModificationsForObject

    0x0000000140544CE0 (Unity) Prefab::GetPropertyModificationsForObject

    0x0000000140545240 (Unity) GeneratePropertyDiff

    0x000000014058B40D (Unity) GenerateUndoDiffs

    0x000000014058E2AE (Unity) PropertyDiffUndoRecorder::Flush

    0x000000014173B078 (Unity) Application::TickTimer

    0x000000014180693C (Unity) CrashCallback

    0x0000000141808584 (Unity) WinMain

    0x0000000141AECE74 (Unity) strnlen

    0x00007FFD9C462774 (KERNEL32) BaseThreadInitThunk

    0x00007FFD9D060D51 (ntdll) RtlUserThreadStart

    We can see that this error happens deep inside Unity's own code, with Odin being nowhere in the call stack. Odin sets some Unity prefab modifications manually - this is necessary for it to function. However, the modifications Odin sets are perfectly legal and "regular". However, it seems there is a bug somewhere deep in Unity's prefab modification system that causes this crash, for no particular reason I can ascertain, except that apparently once we've set them the slightly new way in 1.0.5, this stops happening. I'm not sure what I can exactly do about this. I can report it to Unity, but it's such an obscure, difficult to reproduce bug, that's probably in so many Unity versions (has been seen from 5.3 to 2017.1), that it's unlikely we'll see much benefit from this. Still, once I've collated some more data, I'll report it, and we'll see what comes of this.

    When I can, I will dedicate some time to poke at this in various ways and see how it reacts, but I'm reluctant to change how we do it now, as it seems to finally somewhat work, and Unity's prefab system is such a very temperamental beast to deal with.

    In the meantime, I consider this somewhat resolved - as resolved as it's likely to be for quite a while. I'll still leave this around, though. If we don't see more of these crashes for a month or two, as we move further past 1.0.5 and into 1.0.6 and 1.1, I will start considering it resolved for real.

  9. Lukas Martin reporter

    forgot to mention, that call trace is using 5.6.2f1 and the latest odin inspector u sent me (i think is 1.0.5 beta) :)

    EDIT: The only way to avoid the crash, is removing the prefab reference, move the child away from the parent gameObject, do the proper modifications, attach again in the correct hierarchy and Apply the prefab!

  10. Tor Esa Vestergaard

    Did the crash happen after you deliberately "provoked it" by upgrading an old version of your project and messing about, or did it just happen in 1.0.5 on a "virgin" prefab instance that never existed in an older version in Odin?

  11. Lukas Martin reporter

    Well, i've just updated to the latest version my project with odin 1.0.5 (beta) and "provoked it" as you say (there is one and ONLY prefab who causes the crash, if i do a modification or something, with a reference to the prefab, BAM crash!)

    EDIT: For now, i'm going to remove Odin from the master branch, and make custom serializations / drawers for Dictionary<Tkey,TValue>, and do further tests with staging.

  12. Tor Esa Vestergaard

    Okay, using the project you sent me, I seem to have figured out a fix to the bug. I reproduced it very reliably (every single time I tried), but after the fix, I cannot make it happen at all any more. We're submitting the 1.0.5 patch to the asset store tomorrow, most likely, so this fix makes it in! :)

  13. Log in to comment