Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
I get failure of TryGetValue in PushObject results in wrong data being passed back #73
When I have this running under Unity (Mono 2.0) I am catching the following problem ONLY on specific data types. Can anyone confirm, or at least explain the issue to me - I am going to assume a broken VM with broken Equals() implementation.
Any attempt at accessing past x.y results in getting back "y" from LUA.
Here is the code I inserted to find the issue, and it does hit the debug print and when I check types in LUA I get the message above.
======== SOURCE OF ERROR IN CODE:
internal void PushObject (LuaState luaState, object o, string metatable)
I'm seeing a potentially similar thing, where 2 valuetypes that hash to the same number share an object.
I finally got that failing unit test in a PR for you. I'm not sure if the fix will be easy. If it is giving you a lot of trouble let me know and I'll think about a work-around. One workaround would be to ensure to only use C# structs in lua that don't hash to the same value (ie. override GetHashCode to use a more class-like hashing function).
I have to say my understanding of hashing/struct/class/equality in C# is not 100%
This caused huge issues in Oxide (https://github.com/RustOxide/Oxide, http://rustoxide.com). LucienMP's fix (implemented in LucienMP@866b842) has stopped the described problem from occuring and has been very widely stress tested. I'm a bit fuzzy on the details now as it's been a while since I looked at this problem, but if the solution committed above can be made less hacky that would be great.
Just to clarify, the issue lies with the fact we're using a very old version of mono (Unity3D's current version) that has a bad implementation of something, it's been fixed in newer versions of mono).