flowkey / UIKit-cross-platform

Cross-platform Swift implementation of UIKit, mostly for Android
MIT License
595 stars 40 forks source link

(Mostly) Android: Fix crashes and render bugs after recreating GLContext #270

Closed ephemer closed 5 years ago

ephemer commented 5 years ago

Fixes #208 (and more)

This is a huge improvement to the way rendering works on Android. Until now we had to reload the entire app when the GLContext was killed (as is the case when minimising the app, entering the task switcher etc).

Instead, we now store the image's source data in CGImage and use it to re-upload the image data onto the GPU when entering the app again, in the newly recreated GLContext. This means the app and all of its state stays loaded at minimal cost (our PNG sources add up to about 100kb RAM usage). It now looks and feels just like an iOS app 🔥

There are also some related changes to font rendering where statically-stored UIFont instances would not render correctly in a newly-created GLContext. UIFont is now a little more separated from FontRenderer: instead of holding a strong reference to a specific FontRenderer, FontRenderers can be recreated behind the scenes and UIFont accesses the relevant FontRenderer instance dynamically. Aside from the rendering improvements (text stays consistently visible!), this should also fix some crashes when cleaning up fonts.

Finally, we are updating sdl-gpu to avoid crashes when "free"ing a GPU_Image that was created in a now-invalid/destroyed GPU_Renderer context. This was causing crashes in over 5% of sessions and will be a huge quality of life improvement for Android users.

Review note:

I tried to make the commit history clean to allow reviewing the different parts of this PR individually, so I can recommend going through each commit one by one.

Important:

We are now using our own fork of sdl-gpu, so you will probably have to run git submodule sync for git to recognise the changed remote.

michaelknoch commented 5 years ago

overall that looks awesomde dude! Booting my android device right now for some testing.