From 7cb7c361f0032ec825360e72b45c4a55c9e73b9e Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Wed, 18 Mar 2020 06:16:34 +0100 Subject: [PATCH] character: Add ability for a streamed frame bitmap to be owned by API user In such case we won't try to free it. --- src/character.c | 16 ++++++++++++---- src/character.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/character.c b/src/character.c index ccddcaa..c61c028 100644 --- a/src/character.c +++ b/src/character.c @@ -53,7 +53,9 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac character->reversing = tmp->reversed ^ reversed; if (tmp->stream) { if (character->spritesheet && character->spritesheet->stream && character->frame) { - al_destroy_bitmap(character->frame->bitmap); + if (character->frame->owned) { + al_destroy_bitmap(character->frame->bitmap); + } al_destroy_bitmap(character->frame->_priv.image); free(character->frame); } @@ -175,7 +177,9 @@ SYMBOL_EXPORT void UnloadSpritesheets(struct Game* game, struct Character* chara if (tmp->frames[i]._priv.filepath) { RemoveBitmap(game, tmp->frames[i]._priv.filepath); } else { - al_destroy_bitmap(tmp->frames[i].bitmap); + if (tmp->frames[i].owned) { + al_destroy_bitmap(tmp->frames[i].bitmap); + } } al_destroy_bitmap(tmp->frames[i]._priv.image); } @@ -515,7 +519,9 @@ SYMBOL_EXPORT void DestroyCharacter(struct Game* game, struct Character* charact if (character->spritesheet && character->spritesheet->stream) { if (character->frame) { - al_destroy_bitmap(character->frame->bitmap); + if (character->frame->owned) { + al_destroy_bitmap(character->frame->bitmap); + } al_destroy_bitmap(character->frame->_priv.image); free(character->frame); } @@ -679,7 +685,9 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact if (!reachedEnd && pos != character->pos) { pos = character->pos; double duration = character->frame->duration; - al_destroy_bitmap(character->frame->bitmap); + if (character->frame->owned) { + al_destroy_bitmap(character->frame->bitmap); + } al_destroy_bitmap(character->frame->_priv.image); free(character->frame); character->frame = calloc(1, sizeof(struct SpritesheetFrame)); diff --git a/src/character.h b/src/character.h index 4301844..61d8f84 100644 --- a/src/character.h +++ b/src/character.h @@ -41,6 +41,7 @@ struct SpritesheetFrame { bool start; bool end; bool shared; + bool owned; struct { ALLEGRO_BITMAP* image;