Skip to content

Commit

Permalink
CanvasGraphics, CairoGraphics: set private static graphics to null be…
Browse files Browse the repository at this point in the history
…fore returning from hitTest()

It can look like a memory leak, when a Graphics object and its owner are held in a static variable. Another hitTest() should clear it, but best to allow GC sooner rather than later.
  • Loading branch information
joshtynjala committed May 24, 2024
1 parent b99d780 commit ecdabf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/openfl/display/_internal/CairoGraphics.hx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class CairoGraphics

if (graphics.__commands.length == 0 || bounds == null || bounds.width == 0 || bounds.height == 0 || !bounds.contains(x, y))
{
CairoGraphics.graphics = null;
return false;
}
else
Expand Down Expand Up @@ -303,6 +304,7 @@ class CairoGraphics
if (hasFill && cairo.inFill(x, y))
{
data.destroy();
CairoGraphics.graphics = null;
return true;
}

Expand All @@ -311,6 +313,7 @@ class CairoGraphics
if (hasStroke && cairo.inStroke(x, y))
{
data.destroy();
CairoGraphics.graphics = null;
return true;
}

Expand All @@ -323,6 +326,7 @@ class CairoGraphics
if (hasFill && cairo.inFill(x, y))
{
data.destroy();
CairoGraphics.graphics = null;
return true;
}

Expand All @@ -331,6 +335,7 @@ class CairoGraphics
if (hasStroke && cairo.inStroke(x, y))
{
data.destroy();
CairoGraphics.graphics = null;
return true;
}

Expand Down Expand Up @@ -418,6 +423,7 @@ class CairoGraphics

data.destroy();

CairoGraphics.graphics = null;
return hitTest;
}
#end
Expand Down Expand Up @@ -1154,7 +1160,11 @@ class CairoGraphics

graphics.__update(renderer.__worldTransform, pixelRatio);

if (!graphics.__softwareDirty || graphics.__managed) return;
if (!graphics.__softwareDirty || graphics.__managed)
{
CairoGraphics.graphics = null;
return;
}

bounds = graphics.__bounds;

Expand Down Expand Up @@ -1437,6 +1447,7 @@ class CairoGraphics

graphics.__softwareDirty = false;
graphics.__dirty = false;
CairoGraphics.graphics = null;
#end
}

Expand Down
7 changes: 7 additions & 0 deletions src/openfl/display/_internal/CanvasGraphics.hx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class CanvasGraphics

if (graphics.__commands.length == 0 || bounds == null || bounds.width <= 0 || bounds.height <= 0)
{
CanvasGraphics.graphics = null;
return false;
}
else
Expand Down Expand Up @@ -331,6 +332,7 @@ class CanvasGraphics
data.destroy();
graphics.__canvas = cacheCanvas;
graphics.__context = cacheContext;
CanvasGraphics.graphics = null;
return true;
}

Expand All @@ -341,6 +343,7 @@ class CanvasGraphics
data.destroy();
graphics.__canvas = cacheCanvas;
graphics.__context = cacheContext;
CanvasGraphics.graphics = null;
return true;
}

Expand All @@ -355,6 +358,7 @@ class CanvasGraphics
data.destroy();
graphics.__canvas = cacheCanvas;
graphics.__context = cacheContext;
CanvasGraphics.graphics = null;
return true;
}

Expand All @@ -365,6 +369,7 @@ class CanvasGraphics
data.destroy();
graphics.__canvas = cacheCanvas;
graphics.__context = cacheContext;
CanvasGraphics.graphics = null;
return true;
}

Expand Down Expand Up @@ -452,6 +457,7 @@ class CanvasGraphics

graphics.__canvas = cacheCanvas;
graphics.__context = cacheContext;
CanvasGraphics.graphics = null;
return hitTest;
}
#end
Expand Down Expand Up @@ -1460,6 +1466,7 @@ class CanvasGraphics

graphics.__softwareDirty = false;
graphics.__dirty = false;
CanvasGraphics.graphics = null;
}
#end
}
Expand Down

0 comments on commit ecdabf3

Please sign in to comment.