I am trying to create an OpenGL library for KMM Compose. This wraps GLSurfaceView
on Android and GLKView
/GLKViewController
on iOS. I have large parts of this working including the entire OpenGL API itself. But that was when I was using a Swift layout instead of Compose layout on iOS. I am now making the iOS side use Compose and things are crashing… (the Android-Compose version works just fine).
I am using nearly the same components as I did before, but the GLKViewController
is now wrapped in UIKitViewController
so it is Composable. After 200-300 frames the program crashes.
When debugging with Xcode, the exception is a BAD_ACCESS exception. When I have the frame counter variable, the BAD_ACCESS exception happens on the Kotlin variable used to count the frames. When that variable is not used, it happens in main
. When turning on Zombie Objects, the error does change, indicating to me that there is some object being cleaned up but that is actually still in use.
A minimal testing app is available at
github.com/coderforlife/kmm-gl-test. It is based on the KMM Compose template and should draw a green rectangle that is 50% of the screen size. This does not include the cross-platform GL library, but exhibits the bug with the GLKView
/GLKViewController
.
Note: the purpose of this 3D graphics is NOT full-screen and the entire app is not using OpenGL thus why this is also supporting Compose. If it was full-screen and always OpenGL then it would just jump straight into the single component and never need Compose.