-
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
Fix #1986 #1990
Fix #1986 #1990
Conversation
This might fall under the category of refactoring, but there is potential for a cleaner and faster solution here. Having (Some hastily written and untested code for clarity.) public function remove<T:FlxObject>(Object:T):T {
if (_registeredObjects == null || _registeredObjects.length == 0) { return Object; }
for (reg in _registeredObjects) {
if (reg.object == Object) {
reg.destroy();
_registeredObjects.remove(reg);
break;
}
}
return Object;
}
public function removeAll():Void {
if (_registeredObjects == null || _registeredObjects.length == 0) { return; }
for (reg in _registeredObjects) { reg.destroy(); }
_registeredObjects = [];
}
// . . .
public function destroy():Void {
object = null; sprite = null;
onMouseDown = onMouseUp = onMouseOver = onMouseOut = null;
} Just something to consider. Although, it sounds like there might be other parts of the project that could be improved with the same refactoring, which would be beyond the scope of the issue you are fixing. Edit: Added a |
I agree, there are plenty of places where removal logic should be changed. You should make a new issue for it 😁 |
@seraku24 Have you actually tried this fix yet? It properly removes all registered objects, but I don't have your code to see if that was causing your specific issue. |
Oh crap I mixed up my tabs |
This PR is good to go, fixes #1986 according to OP of that thread |
I didn't really doubt that it fixes the issue (the test case from the issue doesn't crash anymore), I just didn't think your explanation of why it fixes it makes sense. |
@Beeblerox yeah, #2005 solves the larger problem. Close this and leave it to that issue? @Gama11 you're right, I'm not sure why |
Closes #1986
Iterating while removing, change taken from
Watch
. I'm not sure if copying is the best way vs iterating twice, but this makes it consistent with other parts of flixel.