Loading Screen Improvements/Fix Crashes #41
Labels
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: SketchyMaze/doodle#41
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
With the recently added loading screen, gameplay becomes unstable and can crash when transitioning between Edit and Play modes:
The root cause is that the setupAsync() functions on the Play and Edit Mode runs on a background goroutine to load the level and pre-render its chunks while not blocking the main thread; without the goroutine, the main thread hangs until loading is 100% completed and the load screen UX never even got a chance to draw!
Similar crashes used to affect the Level Chunker when it pre-computed its chunks: on the goroutine this would happen off the main thread and crash. The Chunker updated to separate the "bitmap generation" phase from the "SDL2 texture loader" phase -- the latter only happens at runtime when the chunk is being made visible on the screen (main thread) and at that point it just loads the pre-made bitmap image into the Texture.
Similar treatment can be applied to Wallpapers and Sprite Images: there must be a separation between preparing a bitmap image in memory and postpone texture loading until needed, on the main thread.
Wallpaper
The Wallpaper struct already has these properties:
The series of events starting in setupAsync seems to be:
Canvas.PresentWallpaper() is where the wallpaper textures actually get blotted to the screen, on the main thread, and ideally is where the textures should be lazy loaded from pre-cached bitmaps at.
Some things to change:
Sprite Images
The editor scene uses sprite images for the toolbar icons.
In EditorUI.SetupToolbar() it calls sprites.LoadImage() to get a *UI.Image to use as the child widget of a ui.RadioButton.
pkg/sprites/sprites.go#LoadImage(Engine, filename) decodes the PNG image and then attempts to Engine.StoreTexture() immediately, which will fail on non-main thread, before returning ui.ImageFromTexture() to get the ui.Image widget.
The fix should probably live closer to ui.Image itself:
Changes in the game's code would be: