You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unity & Messagepack v2.x Error on some Android devices. #748
Just built a Android version with the new message pack v2.x on an Android device (iOS is working fine - both using IL2CPP). As soon as I call this line
Plugins: Couldn't open advapi32, error: dlopen failed: library "advapi32" not found
Repro steps
Tested on an Android 6.0 and 8.0 device with different API Levels 23 and 27 crashed, 26 was fine - so it is also not related to any specific Android API Level or Android Version...
Expected behavior
Should not crash.
Actual behavior
Program crashes.
Version used: Unity 2019.2.16f1 with MessagePack v2.0.323 (unity package)
That is all information I can get when debugging with Android device connected to unity. This is a warning message from unity and right after that message the android device is saying "App is closed" - no more information given. I guess I need to check if I can get more info via adb log from android device itself - ill check that.
It is deserialising stuff, but it appears to be the date time ! Interesting is that when looking for advapi32 errors in google, I can find an recent issue with unity:
I can confirm using DateTime.Now does not cause any problems here... - very strange... so it must be related to how message pack is using it somehow... -> Unsafe_ReadUnaligned_TisInt64 ?
changed the title [-]Unity & Messagepack v2.x Error on Android devices.[/-][+]Unity & Messagepack v2.x Error on some Android devices.[/+]on Dec 29, 2019
@AArnott
I guess it's a Unity IL2CPP VM issue.
In that case, the details are a black box,
so you have to create a reproduction procedure and report a bug to Unity.
Unsafe.dll is not usually used in Unity, so it's no wonder bugs exist in the IL2CPP VM.
However, if this always happens, Details and workarounds must be sought.
However, I and several companies have already tried v2 on Android,
I have not received a similar report.
Therefore, we cannot assert that there is a problem.
Well unsafe is checked in unity for Android and since it’s working on a few devices and on iOS it seems to be fine overal. Maybe you can reproduce it with some datetime in messagepack classes because that is where it crashes but it definitely a combination from messagepack and unity. The crash happens in deserialize and i have now moved back to v1.8 - all fine again- because many had this crash with several different Android device new and old. 😥
So as soon as message pack is trying to deserialise the datetime in unity via this unsafe.dll - that is the point where it is fatal crashing on some devices. Removing this DateTime prevents it from crashing.
Maybe this helps in reproduction...?
From MessagePackGenerated.cs (that where it seems to crash...)
Since DateTime.Now is not used, I don't think it has a direct effect, but I think it is a similar problem.
Unity says Fixed in 2019.3, and you're trying in 2019.2,
Could you check in 2019.3?
Wow great research here :) and finally we can hope for a fix sooner or later in this regard, so people can use 2.0 with unity. I still wonder why there are not a lot more people having issues with messaepack 2.0 and unity - because ARMv7 is still heavily used and this seems to be a general problems with datetime and doubles...
Currently supporting 64bit architecture is must on upload to Google Play Store.
Most of me and my customers have already not support ARMv7.
Therefore, the priority was not high.
The solution is to replace this with managed code.
@neuecc We develop the game with 700к daily active users on Android. I prepare statistic about CPU architectures distribution in it:
17-18% of ARMv7 it's also quite a lot.
Also, i sent repro project to Unity. I'll keep you informed about it.
I totally agree ARMv7, even if it outdated, is still in heavy use, as mentioned by Durnev. Yes you need 64bit support, but if you want higher reach there is no way around to also support ARMv7.
In my eyes at the current stage, Message Pack 2.0 is absolutely not usable with unity, due to this issue. Well its no problem for me to stay on old version... but still I think this needs to get fixed or otherwise people need to be aware that Messagepack 2.0 is not working on ARMv7 devices with unity.
Hey there, that sounds great (!), I did not have time to try it out yet - have to do migration again. Maybe I can do it later today, then I can give you feedback if it is working.
Hello.
I have answer from Unity support team about our issue.
ARMv7 requires for all reads to be aligned.
In SequenceReaderExtensions.cs on line 43, there is this call made Unsafe.ReadUnaligned<T>(ref MemoryMarshal.GetReference(span));. It gets there from TryReadBigEndian() -> TryReadReverseEndianness() -> TryRead().
IL2CPP does the right thing here as it stops the memory being accessed from an unaligned read, while when using mono, that is ignored and the program returns garbage values.
I haven't found a ReadAligned method which would allow the user to read in an aligned way from the memory. The best solution would be implementing ReadAligned by yourself.
So rewrite this code was right solution by @neuecc. We can wait until ARMv7 will be deprecated, but i think it will be not near future.
Activity
AArnott commentedon Dec 29, 2019
Can you please include the full callstack from the exception?
odysoftware commentedon Dec 29, 2019
That is all information I can get when debugging with Android device connected to unity. This is a warning message from unity and right after that message the android device is saying "App is closed" - no more information given. I guess I need to check if I can get more info via adb log from android device itself - ill check that.
AArnott commentedon Dec 29, 2019
Ya, anything else you can give would be great. Messagepack has no direct reference to advapi32 so it's probably something else that's failing.
odysoftware commentedon Dec 29, 2019
So with Android and symbols the best I can get is:
It is deserialising stuff, but it appears to be the date time ! Interesting is that when looking for advapi32 errors in google, I can find an recent issue with unity:
https://issuetracker.unity3d.com/issues/unable-to-load-dll-advapi32-dot-dll-when-calling-datetime-dot-now
I have to check but I am using datetime.now too and there I don't have problems... very strange...
odysoftware commentedon Dec 29, 2019
I can confirm using DateTime.Now does not cause any problems here... - very strange... so it must be related to how message pack is using it somehow... -> Unsafe_ReadUnaligned_TisInt64 ?
[-]Unity & Messagepack v2.x Error on Android devices.[/-][+]Unity & Messagepack v2.x Error on some Android devices.[/+]AArnott commentedon Dec 30, 2019
Thanks. This is helpful. Where did you get your Unsafe.dll? I wonder if you're shipping one with your Android app that is compiled for Windows.
neuecc commentedon Dec 30, 2019
Stack trace is mentioned
Unsafe.ReadUnaligned<long>was crashed.I think
Unsafe.dllis managed dll, it is no dependent platform.AArnott commentedon Dec 30, 2019
@neuecc Are you saying that advapi32.dll is unrelated?
neuecc commentedon Dec 30, 2019
@AArnott
I guess it's a Unity IL2CPP VM issue.
In that case, the details are a black box,
so you have to create a reproduction procedure and report a bug to Unity.
neuecc commentedon Dec 30, 2019
Unsafe.dllis not usually used in Unity, so it's no wonder bugs exist in the IL2CPP VM.However, if this always happens, Details and workarounds must be sought.
However, I and several companies have already tried v2 on Android,
I have not received a similar report.
Therefore, we cannot assert that there is a problem.
odysoftware commentedon Dec 30, 2019
Well unsafe is checked in unity for Android and since it’s working on a few devices and on iOS it seems to be fine overal. Maybe you can reproduce it with some datetime in messagepack classes because that is where it crashes but it definitely a combination from messagepack and unity. The crash happens in deserialize and i have now moved back to v1.8 - all fine again- because many had this crash with several different Android device new and old. 😥
odysoftware commentedon Dec 30, 2019
I can try to look what exactly in my class using message pack is causing this, that should help for reproduction.
Maybe it’s related to this same unity issue https://issuetracker.unity3d.com/issues/unable-to-load-dll-advapi32-dot-dll-when-calling-datetime-dot-now
odysoftware commentedon Dec 30, 2019
What I can see is that it is only happening for the datetime type...
e.g.
So as soon as message pack is trying to deserialise the datetime in unity via this unsafe.dll - that is the point where it is fatal crashing on some devices. Removing this DateTime prevents it from crashing.
Maybe this helps in reproduction...?
From MessagePackGenerated.cs (that where it seems to crash...)
neuecc commentedon Dec 31, 2019
Since DateTime.Now is not used, I don't think it has a direct effect, but I think it is a similar problem.
Unity says
Fixed in 2019.3, and you're trying in2019.2,Could you check in
2019.3?14 remaining items
Durnev commentedon Jan 27, 2020
I found out that crash appears if we call
TryReadonSequenceReaderto read byte with MP code.I replaced
doublewithlongand it also crashed. I think problem is inSequenceReader.It can be memory alignment issue, but my experience is not enough to continue research.
Also, i have a problems with debugging code in

SequenceReader.odysoftware commentedon Jan 27, 2020
Wow great research here :) and finally we can hope for a fix sooner or later in this regard, so people can use 2.0 with unity. I still wonder why there are not a lot more people having issues with messaepack 2.0 and unity - because ARMv7 is still heavily used and this seems to be a general problems with datetime and doubles...
Anyway I hope someone can catch it now!
neuecc commentedon Jan 27, 2020
Currently supporting 64bit architecture is must on upload to Google Play Store.
Most of me and my customers have already not support ARMv7.
Therefore, the priority was not high.
The solution is to replace this with managed code.
Durnev commentedon Jan 28, 2020
@neuecc We develop the game with 700к daily active users on Android. I prepare statistic about CPU architectures distribution in it:

17-18% of ARMv7 it's also quite a lot.
Also, i sent repro project to Unity. I'll keep you informed about it.
odysoftware commentedon Jan 28, 2020
I totally agree ARMv7, even if it outdated, is still in heavy use, as mentioned by Durnev. Yes you need 64bit support, but if you want higher reach there is no way around to also support ARMv7.
In my eyes at the current stage, Message Pack 2.0 is absolutely not usable with unity, due to this issue. Well its no problem for me to stay on old version... but still I think this needs to get fixed or otherwise people need to be aware that Messagepack 2.0 is not working on ARMv7 devices with unity.
neuecc commentedon Jan 29, 2020
thanks for the details.
I've added PR, I don't confirm yet but maybe fixed.
AArnott commentedon Jan 29, 2020
@odysoftware can you confirm with the build in #795 PR that it fixes your issue?
Also, can you link to a bug tracking this in Unity if you have one?
odysoftware commentedon Jan 31, 2020
Hey there, that sounds great (!), I did not have time to try it out yet - have to do migration again. Maybe I can do it later today, then I can give you feedback if it is working.
odysoftware commentedon Jan 31, 2020
So far everything seems fine, now starting tests on Android !
There was a mistake though in SequenceReaderExtensions.cs when switching unity to Android ->
This gives an error, you need to change it to:
then it works.
odysoftware commentedon Jan 31, 2020
It didn't help for all problems yet because the datetime is not calling new method so I still have this crash - it may only work for doubles:
So we need this also for the other types?
Durnev commentedon Feb 3, 2020
Hello.
I have answer from Unity support team about our issue.
So rewrite this code was right solution by @neuecc. We can wait until ARMv7 will be deprecated, but i think it will be not near future.
neuecc commentedon Mar 18, 2020
solved by #798
Avoid using MemoryMarshal.Cast<byte, _> on Android
Avoid using MemoryMarshal.Cast<byte, _> on Android