-
Notifications
You must be signed in to change notification settings - Fork 459
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
FlxMouseEventManager.removeAll() fails to completely unregister even number of objects #1986
Comments
The issue internally is that |
Cool, thanks! |
@MSGhero That explanation doesn't make sense to me. A new array is assigned to |
If not, this at least fixes the memory that isn't cleaned up when "removing while iterating" skips elements. |
It just removes and nulls the members (and it's debatable whether that really helps garbage collection). |
I guess this should actually be tested. I wrote that fix really quickly between classes but haven't had a chance to try it out. |
@SamBumgardner can you try the fix in #1990 and see if that resolves your issues? It needs to be fixed regardless, but I want to know if this is the actual issue you were having. |
Sure, I'll check it out. |
It only took 20 days for me to find some free time haha... |
No worries! It looks to me like the issue is fixed. The code snippet that I posted with the issue is fine now, and my larger project isn't running into any problems either. Thanks a bunch for fixing it! |
I want to look into this again. It shouldn't be necessary to call |
Yeah, it seems the issue persists if you get rid of the |
Code snippet reproducing the issue:
Observed behavior:
I registered a pair of
FlxSprite
s to theFlxMouseEventManager
, setting itsmouseUp
function to switch between states and itsmouseOut
function to call one of the sprite's variable's functions. I also overrode the starting state'sswitchTo
to callFlxMouseEventManager
'sremoveAll
function, so the buttons should be removed fromFlxMouseEventManager
whenever the state switch occurs.When the game switches between states, it properly removes the second
FlxSprite
, but it fails to remove the first. If the second sprite was clicked, everything's fine. If the first sprite was clicked, however, itsmouseOut
function is called after the state switch finishes. Since the registeredmouseOut
function interacts with one of the sprite's variables that was set tonull
during the state change, the game crashes.As far as I can tell, this always happens if an even number of objects are registered to the
FlxMouseEventManager
.If you have an odd number of objects registered to the
FlxMouseEventManager
, no problem occurs. You can try it by uncommenting the lineFlxMouseEventManager.add(spr3);
Expected behavior:
I expected that all registered objects would be removed from
FlxMouseEventManager
byremoveAll()
, regardless of whether number of objects is even or odd.Side note: I did find a workaround. By removing the
FlxMouseEventManager
plugin from FlxG and then calling itsinit()
, I could force theFlxMouseEventManager
to clear itself completely. It may also be possible that removing instances one by one works, but I haven't tried it yet.The text was updated successfully, but these errors were encountered: