mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-07-01 14:15:16 +02:00
Fix memory leak when disposing a high-res Bitmap
This commit is contained in:
parent
8fcd6dd605
commit
83647b947d
3 changed files with 31 additions and 0 deletions
|
@ -805,6 +805,8 @@ Bitmap::Bitmap(SDL_Surface *imgSurf, SDL_Surface *imgSurfHires, bool forceMega)
|
||||||
Bitmap::~Bitmap()
|
Bitmap::~Bitmap()
|
||||||
{
|
{
|
||||||
dispose();
|
dispose();
|
||||||
|
|
||||||
|
loresDispCon.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool forceMega)
|
void Bitmap::initFromSurface(SDL_Surface *imgSurf, Bitmap *hiresBitmap, bool forceMega)
|
||||||
|
@ -897,6 +899,7 @@ void Bitmap::setLores(Bitmap *lores) {
|
||||||
guardDisposed();
|
guardDisposed();
|
||||||
|
|
||||||
p->selfLores = lores;
|
p->selfLores = lores;
|
||||||
|
loresDispCon = lores->wasDisposed.connect(&Bitmap::loresDisposal, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bitmap::isMega() const{
|
bool Bitmap::isMega() const{
|
||||||
|
@ -2603,3 +2606,9 @@ void Bitmap::releaseResources()
|
||||||
|
|
||||||
delete p;
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bitmap::loresDisposal()
|
||||||
|
{
|
||||||
|
loresDispCon.disconnect();
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
|
@ -171,9 +171,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void releaseResources();
|
void releaseResources();
|
||||||
|
sigslot::connection loresDispCon;
|
||||||
const char *klassName() const { return "bitmap"; }
|
const char *klassName() const { return "bitmap"; }
|
||||||
|
|
||||||
BitmapPrivate *p;
|
BitmapPrivate *p;
|
||||||
|
|
||||||
|
void loresDisposal();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITMAP_H
|
#endif // BITMAP_H
|
||||||
|
|
|
@ -395,6 +395,25 @@ dump(bmp, spr, "draw-text-green-outline")
|
||||||
|
|
||||||
# TODO: Animation tests, if we can find a good way to test them.
|
# 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
|
# Tests are finished, show exit screen
|
||||||
|
|
||||||
bmp = Bitmap.new(640, 480)
|
bmp = Bitmap.new(640, 480)
|
||||||
|
|
Loading…
Add table
Reference in a new issue