From 8552a45fd9a086c472cf76138837a56039583ee6 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 11 Nov 2024 17:10:08 +0100 Subject: [PATCH] Fix crash when using a hue changed enemy Thats another regression caused by the requirement of an ID for the SpriteEffect. Replaced the assert with a debug log as this already caused 3 issues. --- src/cache.cpp | 12 +++++++++--- src/game_pictures.cpp | 2 +- src/sprite_enemy.cpp | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cache.cpp b/src/cache.cpp index 4d54b1eb70..b9d36d5e4a 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -463,8 +463,16 @@ BitmapRef Cache::Tile(StringView filename, int tile_id) { } BitmapRef Cache::SpriteEffect(const BitmapRef& src_bitmap, const Rect& rect, bool flip_x, bool flip_y, const Tone& tone, const Color& blend) { + std::string id = ToString(src_bitmap->GetId()); + + if (id.empty()) { + // assert caused too many regressions, use the pointer as the unique key and log instead + Output::Debug("Bitmap has no ID. Please report a bug!"); + id = fmt::format("{}", (void*)(src_bitmap.get())); + } + const effect_key_type key { - src_bitmap->GetId(), + id, src_bitmap->GetTransparent(), rect, flip_x, @@ -473,8 +481,6 @@ BitmapRef Cache::SpriteEffect(const BitmapRef& src_bitmap, const Rect& rect, boo blend }; - assert(!src_bitmap->GetId().empty()); - const auto it = cache_effects.find(key); if (it == cache_effects.end() || it->second.expired()) { diff --git a/src/game_pictures.cpp b/src/game_pictures.cpp index c2e92a2fbe..19e6591672 100644 --- a/src/game_pictures.cpp +++ b/src/game_pictures.cpp @@ -499,7 +499,7 @@ void Game_Pictures::Picture::AttachWindow(const Window_Base& window) { CreateSprite(); auto bmp = std::make_shared(window.GetWidth(), window.GetHeight(), data.use_transparent_color); - bmp->SetId(fmt::format("W:{}{}{}", (void*)&window, window.GetWidth(), window.GetHeight())); + bmp->SetId(fmt::format("Window:addr={},w={},h={}", (void*)&window, window.GetWidth(), window.GetHeight())); sprite->SetBitmap(bmp); sprite->OnPictureShow(); diff --git a/src/sprite_enemy.cpp b/src/sprite_enemy.cpp index 3214316051..1db6398cca 100644 --- a/src/sprite_enemy.cpp +++ b/src/sprite_enemy.cpp @@ -79,6 +79,7 @@ void Sprite_Enemy::OnMonsterSpriteReady(FileRequestResult* result) { if (hue_change) { BitmapRef new_graphic = Bitmap::Create(graphic->GetWidth(), graphic->GetHeight()); new_graphic->HueChangeBlit(0, 0, *graphic, graphic->GetRect(), hue); + new_graphic->SetId(fmt::format("{},hue={}", graphic->GetId(), hue)); graphic = new_graphic; }