Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in OnAfterDeserialize #10

Open
Haaxor1689 opened this issue May 3, 2019 · 3 comments
Open

NullReferenceException in OnAfterDeserialize #10

Haaxor1689 opened this issue May 3, 2019 · 3 comments

Comments

@Haaxor1689
Copy link

Haaxor1689 commented May 3, 2019

I'm getting a NullReferenceException from OnAfterDeserialize method. Here is the full stack trace:

NullReferenceException: Object reference not set to an instance of an object
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <ac823e2bb42b41bda67924a45a0173c3>:0)
SerializableDictionaryBase`3[TKey,TValue,TValueStorage].OnAfterDeserialize () (at Assets/SerializableDictionary/SerializableDictionary.cs:30)

When debugging the code it seems that both m_keys and m_values contain correct serialized values. From what I was able to find online, this could be somehow connected to the dictionary being accessed from multiple threads, which I'm not sure if it's the case with Unity's serialization system.

Here is a link to the source code and a dictionary that is giving me the exception:
Dictionary
Place where it is serialized

@azixMcAze
Copy link
Owner

Hi!
I could not find where you use a SerializableDictionnary in the links and the first one is not working.
Can you reproduce the error on a more simple example ?

@Haaxor1689
Copy link
Author

Oh those links point to newest commits and I have changed the implementation since then. Here you can see the new implementation. I've implemented the ISerializationCallbackReceiver myself and different to your implementation inside OnAfterDeserialize I'm creating new instance of dictionary which doesn't throw any exceptions when adding elements to it.

@ilterbilguven
Copy link

I got this error in the case below:
The dictionary's key is an object that can be null (e.g. Transform)
In a script attached to a gameobject, when dictionary's key is null, it gives this exception while loading the gameobject

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants