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

Conversation

EliteMasterEric
Copy link
Contributor

When attempting to render a destroyed graphic (which is wrong and the library user needs to diagnose the issue), determining which sprite was the cause of the issue is difficult, due to the error taking place long after the draw is queued. This change ensures that the error is thrown WHEN the sprite's draw() call is performed rather than after; this allows developers to step up to FlxSprite.draw() when debugging and view the affected sprite in the local variable scope.

Copy link
Member

@Geokureli Geokureli left a comment

Choose a reason for hiding this comment

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

see comments below also:

I'm wondering if we should do something even sooner, perhaps we should check in draw(), check whether the sprite was destroyed or the graphic, use FlxG.log.error, and then set the sprite's visible to false to prevent repeating errors?

@@ -635,6 +635,11 @@ class FlxCamera extends FlxBasic
itemToReturn = new FlxDrawItem();
}

if (graphic.wasDestroyed) {
// 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

@@ -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

*/
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

@@ -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 (shader == null) {
// 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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants