Closed tayl0r closed 5 years ago
Thanks for the report and reproduction case, @tayl0r. I initially had some trouble reproducing this but see the issue (at least on older devices).
The object references are being cleaned up correctly, however it seems that we'll need to set more strict limits for the amount of metadata/breadcrumbs that can be attached to reports for Unity projects as deeply recursive structures are consuming too many references at once.
Update: There is one ref which isn't cleaned up correctly, fixing it reduces the likelihood of hitting this case significantly. Making a patch. ✍️
Description
Call Bugsnag.Notify multiple times per frame will crash the app
Issue
JNI ERROR (app bug): local reference table overflow (max=512) at BugsnagUnity.NativeInterface.DictionaryFromJavaMap (intptr)
It looks like this
DictionaryFromJavaMap()
method inNativeInterface.cs
isn't deleting all the local references it is creating. So if you run it enough in the same frame, it will crash due to this local reference table overflow error.I'm no Android/Java programmer, but I think all of these calls to
CallStringMethod
andCallObjectMethod
need to have their result deleted viaDeleteLocalRef
.I think the crash only happens on older/slower Android devices such as the Nexus 5X running Android OS 7.0. I don't think the Android OS matters though, I have seen the crash also on an Xiaomi Mi 8 running Android OS 9.0 device. But haven't seen the crash on any Android OS 8.0 devices.
Here is a subset of the devices that we've seen the crash on: P9, P9 Lite, Tab A, Intex Aqua Craze, Galaxy Grand 2, S4, Xperia Z2, Le Pro 3, Redmi 4 Pro, Redmi Note 4, Vibe K5. Almost all of those were running Android OS 7.0.
Environment
Example code snippet
To reproduce, you can just open this Unity project, scene "main", then build to your Android device. It will run 20 Bugsnag.Notify() calls which will crash the app. The project is completely empty except for the Bugsnag plugin plus my test code. https://www.dropbox.com/s/43ssyb4kjrmksb4/TestBugsnag.zip?dl=0