Skip to content

Commit

Permalink
Avoid FlxBackdrop matrix leak (#426)
Browse files Browse the repository at this point in the history
* Update FlxBackdrop.hx

* whoops missed these

* revert certain changes, add tileSize.put calls

---------

Co-authored-by: George Kurelic <[email protected]>
  • Loading branch information
MaybeMaru and Geokureli committed Apr 13, 2024
1 parent 0d3b597 commit bc6cd74
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions flixel/addons/display/FlxBackdrop.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FlxBackdrop extends FlxSprite

var _blitOffset:FlxPoint = FlxPoint.get();
var _blitGraphic:FlxGraphic = null;
var _tileMatrix:FlxMatrix = new FlxMatrix();
var _prevDrawParams:BackdropDrawParams =
{
graphicKey:null,
Expand Down Expand Up @@ -82,9 +83,10 @@ class FlxBackdrop extends FlxSprite

override function destroy():Void
{
spacing = FlxDestroyUtil.destroy(spacing);
_blitOffset = FlxDestroyUtil.destroy(_blitOffset);
spacing = FlxDestroyUtil.put(spacing);
_blitOffset = FlxDestroyUtil.put(_blitOffset);
_blitGraphic = FlxDestroyUtil.destroy(_blitGraphic);
_tileMatrix = null;

super.destroy();
}
Expand Down Expand Up @@ -200,7 +202,7 @@ class FlxBackdrop extends FlxSprite
final frame = drawBlit ? _blitGraphic.imageFrame.frame : _frame;

// The distance between repeated sprites, in screen space
var tileSize = FlxPoint.get(frame.frame.width, frame.frame.height);
final tileSize = FlxPoint.get(frame.frame.width, frame.frame.height);
if (drawDirect)
tileSize.addPoint(spacing);

Expand Down Expand Up @@ -256,6 +258,7 @@ class FlxBackdrop extends FlxSprite
}
}

tileSize.put();
camera.buffer.unlock();
}

Expand All @@ -275,7 +278,7 @@ class FlxBackdrop extends FlxSprite
_matrix.translate(-origin.x, -origin.y);

// The distance between repeated sprites, in screen space
var tileSize = FlxPoint.get(frame.frame.width, frame.frame.height);
final tileSize = FlxPoint.get(frame.frame.width, frame.frame.height);

if (drawDirect)
{
Expand Down Expand Up @@ -339,33 +342,33 @@ class FlxBackdrop extends FlxSprite
if (drawBlit)
_point.addPoint(_blitOffset);

final mat = new FlxMatrix();
for (tileX in 0...tilesX)
{
for (tileY in 0...tilesY)
{
mat.copyFrom(_matrix);
_tileMatrix.copyFrom(_matrix);

mat.translate(_point.x + (tileSize.x * tileX), _point.y + (tileSize.y * tileY));
_tileMatrix.translate(_point.x + (tileSize.x * tileX), _point.y + (tileSize.y * tileY));

if (isPixelPerfectRender(camera))
{
mat.tx = Math.floor(mat.tx);
mat.ty = Math.floor(mat.ty);
_tileMatrix.tx = Math.floor(_tileMatrix.tx);
_tileMatrix.ty = Math.floor(_tileMatrix.ty);
}

if (FlxG.renderBlit)
{
final pixels = drawBlit ? _blitGraphic.bitmap: framePixels;
camera.drawPixels(frame, pixels, mat, colorTransform, blend, antialiasing, shader);
camera.drawPixels(frame, pixels, _tileMatrix, colorTransform, blend, antialiasing, shader);
}
else
{
drawItem.addQuad(frame, mat, colorTransform);
drawItem.addQuad(frame, _tileMatrix, colorTransform);
}
}
}

tileSize.put();
if (FlxG.renderBlit)
camera.buffer.unlock();
}
Expand Down

0 comments on commit bc6cd74

Please sign in to comment.