diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index 0ae679572..b2ca66c14 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -831,6 +831,8 @@ Bitmap::Bitmap(SDL_Surface *imgSurf, SDL_Surface *imgSurfHires, bool forceMega) Bitmap::~Bitmap() { dispose(); + + loresDispCon.disconnect(); } void Bitmap::initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool forceMega) @@ -927,6 +929,7 @@ void Bitmap::setLores(Bitmap *lores) { guardDisposed(); p->selfLores = lores; + loresDispCon = lores->wasDisposed.connect(&Bitmap::loresDisposal, this); } bool Bitmap::isMega() const{ @@ -2635,3 +2638,9 @@ void Bitmap::releaseResources() delete p; } + +void Bitmap::loresDisposal() +{ + loresDispCon.disconnect(); + dispose(); +} diff --git a/src/display/bitmap.h b/src/display/bitmap.h index c6082fc8c..a41f271ff 100644 --- a/src/display/bitmap.h +++ b/src/display/bitmap.h @@ -171,9 +171,12 @@ class Bitmap : public Disposable private: void releaseResources(); + sigslot::connection loresDispCon; const char *klassName() const { return "bitmap"; } BitmapPrivate *p; + + void loresDisposal(); }; #endif // BITMAP_H diff --git a/tests/hires-bitmap/hires-bitmap-test.rb b/tests/hires-bitmap/hires-bitmap-test.rb index 3a62d0f9d..ba044cb10 100755 --- a/tests/hires-bitmap/hires-bitmap-test.rb +++ b/tests/hires-bitmap/hires-bitmap-test.rb @@ -395,6 +395,25 @@ def dump(bmp, spr, desc) # TODO: Animation tests, if we can find a good way to test them. +bmp = Bitmap.new(640, 480) +fnt = Font.new("Liberation Sans", 100) +fnt.out_color = Color.new(0, 255, 0) +bmp.font = fnt +bmp.draw_text(100, 200, 450, 300, "Now testing dispose for memory leaks...", 1) +dump(bmp, spr, "memory-leak") + +def allocate() + bmp_allocate = Bitmap.new("Graphics/Pictures/children-alpha") + bmp_allocate.dispose +end + +for i in (1...100) + for j in (1...10) + allocate + end + System::puts("Memory leak test #{i}/100") +end + # Tests are finished, show exit screen bmp = Bitmap.new(640, 480)