GRAPHICS: Fix ManagedSurface::copyFrom memory handling

When calling ManagedSurface::copyFrom, _disposeAfterUse should be set to
YES because inner surface frees up old pixels array and creates a new one.
This commit is contained in:
Le Philousophe 2019-06-09 12:52:20 +02:00 committed by Paul Gilbert
parent bdbad1f3af
commit 1297ae2b76
2 changed files with 12 additions and 4 deletions

View file

@ -124,6 +124,17 @@ void ManagedSurface::free() {
_offsetFromOwner = Common::Point(0, 0); _offsetFromOwner = Common::Point(0, 0);
} }
void ManagedSurface::copyFrom(const ManagedSurface &surf) {
// Surface::copyFrom free pixel pointer so let's free up ManagedSurface to be coherent
free();
_innerSurface.copyFrom(surf._innerSurface);
clearDirtyRects();
// Pixels data is now owned by us
_disposeAfterUse = DisposeAfterUse::YES;
}
bool ManagedSurface::clip(Common::Rect &srcBounds, Common::Rect &destBounds) { bool ManagedSurface::clip(Common::Rect &srcBounds, Common::Rect &destBounds) {
if (destBounds.left >= this->w || destBounds.top >= this->h || if (destBounds.left >= this->w || destBounds.top >= this->h ||
destBounds.right <= 0 || destBounds.bottom <= 0) destBounds.right <= 0 || destBounds.bottom <= 0)

View file

@ -307,10 +307,7 @@ public:
* Copy the data from another Surface, reinitializing the * Copy the data from another Surface, reinitializing the
* surface to match the dimensions of the passed surface * surface to match the dimensions of the passed surface
*/ */
void copyFrom(const ManagedSurface &surf) { void copyFrom(const ManagedSurface &surf);
clearDirtyRects();
_innerSurface.copyFrom(surf._innerSurface);
}
/** /**
* Draw a line. * Draw a line.