Unity-Technologies / uaal-example

Other
733 stars 233 forks source link

UnitySendMessage() Crashes with strings bigger than 1MB #67

Open Niter88 opened 2 years ago

Niter88 commented 2 years ago

I am able to send any sizes of strings from Unity to AndroidStudio via override, but I get a crash you you try to send any string close or bigger than 1MB using the mUnityPlayer.UnitySendMessage() method.

This issue was very hard to track, after some debugging the maximum string length I could safely deliver was 1047500. (actually you can fit 1,048,576 characters on 1MB but anything above 1,047,500 may or not crash) Since there is no fix to this and just one old comment on the forum... (yeah I've lost the link to that)

The workaround: The way to get around it was to divide the strings into pieces of 1 million or less. Upon sending the data to Unity I send a message (JSON) to a method saying how many parts it has. Then I use a cached StringBuilder to append all the parts. Upon appending the last part I proceed with my usual code using the full string.

As this is a private project I will post just a part of the error:

E/CRASH: signal 7 (SIGBUS), code 2 (BUS_ADRERR), fault addr 0x88e07000

E/CRASH: main thread is trapped; signum = 7
E/CRASH: main thread is trapped; signum = 7

E/CRASH: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
E/CRASH: Cause: null pointer dereference