-
Notifications
You must be signed in to change notification settings - Fork 438
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
Various FlxBar fixes #2938
Various FlxBar fixes #2938
Conversation
- Fixed `frontFrames` graphic not registering as being used - Render-method-specific variables are now destroyed correctly - `_frontFrame` is now destroyed when being set to `null` - Fixed `_frontFrame` documentation - Removed redundant `positionOffset = null` code
Can you create an example state that illustrates the issues in the old code that this PR fixes |
Sure: package;
import flixel.FlxG;
import flixel.FlxState;
import flixel.ui.FlxBar;
class PlayState extends FlxState
{
var bar:FlxBar;
override public function create()
{
bar = new FlxBar();
bar.value = 50;
bar.screenCenter();
add(bar);
super.create();
}
@:access(flixel.ui.FlxBar)
override public function update(elapsed:Float)
{
if (bar != null)
{
if (FlxG.keys.justReleased.ONE)
{
// With the old code, the game will now crash when trying to draw the FlxBar,
// as the front/filled graphic has been incorrectly cleared
FlxG.bitmap.clearUnused();
FlxG.log.add('Cleared unused graphics.');
}
else if (FlxG.keys.justReleased.TWO)
{
FlxG.log.add('Destroying the FlxBar...');
final _frontFrame = bar._frontFrame;
bar.destroy();
// With the old code, these variables will not have been set to `null`
if (FlxG.renderTile)
{
FlxG.log.add('frontFrames is null: ${bar.frontFrames == null}');
}
else
{
FlxG.log.add('_emptyBar is null: ${bar._emptyBar == null}');
}
// With the old code, _frontFrame will not have been destroyed
FlxG.log.add('_frontFrame was destroyed: ${_frontFrame.sourceSize == null}');
remove(bar, true);
bar = null;
}
}
super.update(elapsed);
}
} The last change (removed redundant |
if (FlxG.renderTile) | ||
{ | ||
_frontFrame = null; | ||
frontFrames = 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.
Can you shed some light on this change? was renderBlit
a mistake, or was the comment above wrong? why frontFrames instead of _frontFrames?
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.
_frontFrame
and _filledFlxRect
are only used in tile render mode, but the current code mistakenly tries to destroy these when the game is using blit render mode, and vice versa for the variables only used in blit mode. Simply changing line 201 to renderTile
fixes it.
I changed line 203 to frontFrames
as that value is left without being set to null in the current code, and set_frontFrames
will also null out _frontFrame
.
Thanks! |
frontFrames
graphic not changing itsuseCount
(for example, if you added an FlxBar and then calledFlxG.bitmap.clearUnused()
, the front graphic would be destroyed and the game would crash when trying to draw it)_frontFrame
is now destroyed when being set tonull
_frontFrame
documentation referring to it as an FlxSpritepositionOffset = null
code (the variable is already set tonull
earlier in the function)