Skip to content

Commit

Permalink
Effects cache: Fix memory leak
Browse files Browse the repository at this point in the history
The BitmapRef reference counter never reached 0 because it was part of the key, preventing deletion.
Changed it to a pointer. The value is never read so doesn't matter if it becomes stale.

Fix #3163
  • Loading branch information
Ghabry committed Dec 22, 2023
1 parent 77d97bb commit 72749b7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace {
std::unordered_map<tile_key_type, std::weak_ptr<Bitmap>> cache_tiles;

// rect, flip_x, flip_y, tone, blend
using effect_key_type = std::tuple<BitmapRef, Rect, bool, bool, Tone, Color>;
using effect_key_type = std::tuple<Bitmap*, Rect, bool, bool, Tone, Color>;
std::map<effect_key_type, std::weak_ptr<Bitmap>> cache_effects;

std::string system_name;
Expand Down Expand Up @@ -444,7 +444,7 @@ 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) {
const effect_key_type key {
src_bitmap,
src_bitmap.get(),
rect,
flip_x,
flip_y,
Expand Down

0 comments on commit 72749b7

Please sign in to comment.