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

Add graphic.isDestroyed, prevent render crashes #2974

Merged
merged 2 commits into from
Nov 27, 2023

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Nov 27, 2023

Closes #2968

adds graphic.isDestroyed, detects when a destroyed graphic is being drawn, logs an error and displays the flixel logo, instead.

Note to @EliteMasterEric:

  • I went with isDestroyed to match isLoaded and isDumped.
  • I also use FlxG.log.error instead of throwing an error. I try to throw when I want the game to pause right when they did something wrong, not later, when I discover that something previously went wrong

@EliteMasterEric
Copy link
Contributor

If you can successfully revert to rendering the Flixel logo instead of crashing, using Flx.error is way better than throwing, since gracefully handling errors is preferred whenever possible

@Geokureli
Copy link
Member Author

using Flx.error is way better than throwing, since gracefully handling errors is preferred whenever possible

I mostly agree, there are some cases where I may want to be extremely loud about a dev mistake, especially if I can point to the exact offending line. But this issue is hard to predict, we can only detect late symptoms, so, yes

@Geokureli Geokureli merged commit b2984b1 into HaxeFlixel:dev Nov 27, 2023
16 checks passed
@Geokureli
Copy link
Member Author

Geokureli commented Nov 27, 2023

let me know if this works for you

here's my test case for posterity

package states;

import flixel.FlxG;
import flixel.FlxBasic;
import flixel.FlxSprite;

class DestroyedSpriteTestState extends flixel.FlxState
{
	var sprite1 = new FlxSprite(100, 100, "assets/images/haxe.png");
	var sprite2:FlxSprite;
	
	override function create()
	{
		super.create();
		
		add(new FlxSprite(0, 100));
		add(sprite2 = new FlxSprite(100, 0, "assets/images/haxe.png"));
		add(sprite1);
	}
	
	override function update(elapsed:Float)
	{
		if (FlxG.keys.justPressed.SPACE)
			sprite2.destroy();
		
		if (FlxG.keys.justPressed.ENTER)
			FlxG.switchState(new DestroyedSpriteTestState());
	}
	
}

Geokureli added a commit that referenced this pull request Nov 28, 2023
@Geokureli Geokureli added this to the 5.6.0 milestone Dec 13, 2023
@Geokureli Geokureli deleted the isDestroyed branch January 5, 2024 16:48
@Geokureli Geokureli mentioned this pull request Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants