HaxeFlixel / HaxeFlixel/flixel

Crash when FlxMouseEventManager is used to close a substate with animated sprite

Open
#2,201 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

  • Haxe version: 3.4.7
  • Flixel version: 4.5.1
  • OpenFL version: 8.7.0
  • Lime version: 7.2.0
  • Affected targets: All

Code snippet reproducing the issue:

package;

import flixel.FlxSprite;
import flixel.FlxSubState;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.input.mouse.FlxMouseEventManager;
import flixel.util.FlxColor;

/**
 * ...
 * @author Tembac
 */
class Substate extends FlxSubState 
{

	public function new(BGColor:FlxColor=FlxColor.TRANSPARENT) 
	{
		super(BGColor);
		
		var textureFrames:FlxAtlasFrames = FlxAtlasFrames.fromTexturePackerJson("assets/images/popUp.png","assets/images/popUp.json");
		
		var closeSpr:FlxSprite = new FlxSprite(128, 128);
		closeSpr.frames = textureFrames;
		closeSpr.animation.addByNames("normal", ["btnCloseNormal"]);
		closeSpr.animation.addByNames("pressed", ["btnOkNormal"]);
		closeSpr.animation.play("normal");
		closeSpr.resetSizeFromFrame();
		add(closeSpr);

		FlxMouseEventManager.add(closeSpr,
		function onMouseDown(s:FlxSprite)
		{
			s.animation.play("pressed");
		},
		function onMouseUp(s:FlxSprite)
		{
			s.animation.play("normal");
			close();
		},
		null,
		function onMouseOut(s:FlxSprite)
		{
			s.animation.play("normal");
		});
		
	}
	
}

Observed behavior:

There is a null reference crash because the mouse out function doesn´t find the sprite to animate.

Expected behavior:

There is no crash.

Example project:

mouseTest.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with the provided mouseTest.zip project and trace the FlxMouseEventManager callbacks used by the FlxSubState close sprite. Done means closing the substate with the animated sprite no longer causes a null-reference crash in the mouse-out callback.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.