Skip to content

Commit

Permalink
Fix crash when using a hue changed enemy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ghabry committed Nov 11, 2024
1 parent e7767ff commit 8552a45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/game_pictures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void Game_Pictures::Picture::AttachWindow(const Window_Base& window) {
CreateSprite();

auto bmp = std::make_shared<Bitmap>(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();
Expand Down
1 change: 1 addition & 0 deletions src/sprite_enemy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8552a45

Please sign in to comment.