MobiVM / robovm

Ahead of time compiler for JVM bytecode targetting iOS, Mac OSX and Linux
https://mobivm.github.io
966 stars 133 forks source link

Crash after trying to instantiate an invalid UiImage #684

Closed MrStahlfelge closed 1 year ago

MrStahlfelge commented 2 years ago

Issue details

Instantiating a UiImage from a byte array can be done in the following way:

UIImage(NSData(bytearray))

However, it could be that the byte array contains invalid data (no picture, not supported picture etc). In that case, the call crashes with an expected exception (RuntimeException: Objective-C initialization method returned nil).

Problem is that guarding this exception with try/catch does only help for some time. The RoboVM app crashes later. I suspected it is on next GC because the behaviour feels like it, but I could not trigger the crash by caling System.gc()

Reproduction steps/code

The following code will lead to a native crash after some time:

try {
   val image = UIImage(NSData(ByteArray(1)))
} catch (t: Throwable) {
}

Please provide the version of RoboVM, XCode and JDK used

Stacktrace

Native crash