-
Notifications
You must be signed in to change notification settings - Fork 2k
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
MouseJoint Touch Issue #18289
MouseJoint Touch Issue #18289
Conversation
This code ensures that all touch event listeners (TOUCH_START, TOUCH_MOVE, TOUCH_END, and TOUCH_CANCEL) attached to the Canvas node are properly removed when the MouseJoint component is destroyed. Purpose: Prevents touch event listeners from remaining in memory after the MouseJoint is destroyed. Avoids unexpected behavior caused by lingering event handlers that could still trigger interactions. Improves memory management and performance by ensuring proper cleanup of event listeners.
|
canvas.off(NodeEventType.TOUCH_MOVE, this.onTouchMove, this); | ||
canvas.off(NodeEventType.TOUCH_END, this.onTouchEnd, this); | ||
canvas.off(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this); | ||
} |
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.
I think override destroy and disable them in destroy function is better as these listeners are enabled in initialize.
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.
I have update the code as per instruction @minggo , Please review the code again. If there is no issue, pl merge it.
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.
@gt3mb Why did you override _destroy
for box2d backend while overriding destroy
for box2d-wasm backend?
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.
onTouchEnd invokes _destroy which will cause the listeners be removed immediately. But in fact, they should only be removed while MouseJoint2D component is destroyed.
I cherry-picked the commits of your PR and sent another one: |
This code ensures that all touch event listeners (TOUCH_START, TOUCH_MOVE, TOUCH_END, and TOUCH_CANCEL) attached to the Canvas node are properly removed when the MouseJoint component is destroyed.
Purpose:
Prevents touch event listeners from remaining in memory after the MouseJoint is destroyed. Avoids unexpected behavior caused by lingering event handlers that could still trigger interactions. Improves memory management and performance by ensuring proper cleanup of event listeners.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: