-
Notifications
You must be signed in to change notification settings - Fork 450
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
Implement wasDestroyed
check on FlxGraphic
#2968
Conversation
There was a problem hiding this 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?'; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no cuddling
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the word "destroy"
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 toFlxSprite.draw()
when debugging and view the affected sprite in the local variable scope.