From 21f7424f89aabb29ccfe0d4eddd80307806a8951 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 19 Mar 2020 02:45:22 +0100 Subject: [PATCH] character: Take ownership of frame bitmaps when preloading streamed spritesheets Since a non-owned frame is valid only until the next invocation of stream callback, we need to clone it and take ownership. --- src/character.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/character.c b/src/character.c index c61c028..5865a64 100644 --- a/src/character.c +++ b/src/character.c @@ -230,6 +230,11 @@ SYMBOL_EXPORT void PreloadStreamedSpritesheet(struct Game* game, struct Characte PrintConsole(game, " - frame %d", i); spritesheet->frames[i] = spritesheet->stream(game, delta, spritesheet->stream_data); + if (!spritesheet->frames[i].owned) { + spritesheet->frames[i].bitmap = al_clone_bitmap(spritesheet->frames[i].bitmap); + spritesheet->frames[i].owned = true; + } + spritesheet->frames[i]._priv.image = al_create_sub_bitmap(spritesheet->frames[i].bitmap, spritesheet->frames[i].sx * spritesheet->scale, spritesheet->frames[i].sy * spritesheet->scale, (spritesheet->frames[i].sw > 0) ? (spritesheet->frames[i].sw * spritesheet->scale) : al_get_bitmap_width(spritesheet->frames[i].bitmap), (spritesheet->frames[i].sh > 0) ? (spritesheet->frames[i].sh * spritesheet->scale) : al_get_bitmap_height(spritesheet->frames[i].bitmap)); int width = al_get_bitmap_width(spritesheet->frames[i]._priv.image) / spritesheet->scale + spritesheet->frames[i].x;