HaxeFlixel / HaxeFlixel/flixel
Invalid Bitmap Error when removing glow Filter from a FlxSprite
Open
Nobody has claimed this yet.
- Dominant language
- Haxe
- Stars
- 2.2k
- Forks
- 522
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
- Haxe version: 3.3.0-RC1
- Flixel version: 4.2.0
- OpenFL version: 3.6.1
- Lime version: 2.9.1
- Affected targets: Flash
Code snippet reproducing the issue:
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.graphics.FlxGraphic;
import flixel.system.FlxAssets.GraphicLogo;
import flixel.graphics.frames.FlxFilterFrames;
import flash.filters.BitmapFilter;
import flash.filters.GlowFilter;
/**
* Test project for button glow filter.
* Press "G" on the keyboard to toggle the glow over the flixel icon.
* Removing the glow without the presence of the buffer sprite causes an Invalid Bitmap Error.
* Written by sano98.
*
*/
class PlayState extends FlxState
{
/**
* The test sprite. Press "G" to give it a glow, and again to remove it.
*/
public var testIcon:FlxSprite;
/**
* The "buffer sprite". It's presence keeps the bug from happening.
*/
public var testIcon2:FlxSprite;
/**
* Glow Filter for the flixel icon
*/
public var glowFilter:GlowFilter;
public var filterFrame:FlxFilterFrames;
override public function create():Void
{
FlxG.worldBounds.set( 0, 0, 640, 480);
FlxG.camera.setScrollBoundsRect(0, 0, 640, 480, false);
super.create();
this.bgColor = 0xFF77AAFF;
this.testIcon = new FlxSprite(300, 300, FlxGraphic.fromClass(GraphicLogo));
this.add(this.testIcon);
//Comment this line out to reproduce the bug.
this.testIcon2 = new FlxSprite(300, 300, FlxGraphic.fromClass(GraphicLogo));
this.glowFilter = new GlowFilter(0xFFFFFFFF, 0.8, 5, 5, 3);
this.filterFrame = this.createFilterFrames(this.testIcon);
}
private function createFilterFrames(sprite:FlxSprite):FlxFilterFrames
{
var filterFrames = FlxFilterFrames.fromFrames(sprite.frames, 5, 5, []);
return filterFrames;
}
function updateFilter(spr:FlxSprite, sprFilter:FlxFilterFrames)
{
sprFilter.applyToSprite(spr, false, true);
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
if (FlxG.keys.justPressed.G)
{
if (this.filterFrame.filters.length > 0)
{
this.filterFrame.clearFilters();
this.updateFilter(testIcon, this.filterFrame);
}
else
{
this.filterFrame.addFilter(glowFilter);
this.updateFilter(testIcon, this.filterFrame);
}
}
}
}
Observed behavior:
When the testIcon2 is not initialised, the code crashs with an invalid bitmap error when pressing the "G"-Button on the keyboard for the second time.
Expected behavior:
Pressing G should simply toggle the glow.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Flash-target failure with the supplied PlayState snippet, focusing on FlxFilterFrames.clearFilters(), applyToSprite(), and the FlxSprite frames used by testIcon. Verify that pressing G twice toggles the glow without an Invalid Bitmap error, both with and without testIcon2 initialized.
Written by the indexing model from the issue text.
Assessment
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100