Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement wasDestroyed check on FlxGraphic #2968

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ class FlxCamera extends FlxBasic
itemToReturn = new FlxDrawItem();
}

if (graphic.wasDestroyed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no cuddling

// Throw an exception here, because throwing in `FlxDrawQuadsItem.render()` is not helpful.
throw 'Attempted to queue invalid FlxDrawItem, did you dispose of a cached sprite?';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i want to avoid the word dispose, and just use the word "destroy" consistently. since that's the function they are likely calling

}

itemToReturn.graphics = graphic;
itemToReturn.antialiasing = smooth;
itemToReturn.colored = colored;
Expand Down
10 changes: 10 additions & 0 deletions flixel/graphics/FlxGraphic.hx
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ class FlxGraphic implements IFlxDestroyable
*/
public var atlasFrames(get, never):FlxAtlasFrames;

/**
* This value is `true` if this graphic has been disposed.
* Attempting to render a disposed graphic will cause an error.
*/
public var wasDestroyed(get, never):Bool;

function get_wasDestroyed():Bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no cuddling

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also let's inline this

return shader == null;
}

/**
* Storage for all available frame collection of all types for this graphic object.
*/
Expand Down
6 changes: 6 additions & 0 deletions flixel/graphics/tile/FlxDrawQuadsItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class FlxDrawQuadsItem extends FlxDrawBaseItem<FlxDrawQuadsItem>
return;

var shader = shader != null ? shader : graphics.shader;

if (shader == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no cuddling

// If this gets called, the check for `graphic.wasDestroyed` in FlxCamera failed.
throw 'Attempted to render invalid FlxDrawItem, did you dispose of a cached sprite?';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the word "destroy"

}

shader.bitmap.input = graphics.bitmap;
shader.bitmap.filter = (camera.antialiasing || antialiasing) ? LINEAR : NEAREST;
shader.alpha.value = alphas;
Expand Down
Loading