fix(input): clear PointerEventReceiver events independently of PointerSystem (#3356)#3781
Open
MohammadYusif wants to merge 1 commit into
Open
fix(input): clear PointerEventReceiver events independently of PointerSystem (#3356)#3781MohammadYusif wants to merge 1 commit into
MohammadYusif wants to merge 1 commit into
Conversation
…rSystem (excaliburjs#3356) The PointerEventReceiver accumulates native pointer events in its currentFrame* arrays. These were only ever updated and cleared by PointerSystem.update() each frame. If a scene removed the PointerSystem (e.g. world.remove(world.get(PointerSystem))), nothing flushed those arrays, so they grew without bound on every pointer event - a memory leak. The InputHost now guarantees the receiver is flushed exactly once per frame regardless of whether a PointerSystem is active: the PointerSystem marks each receiver it processes, and the InputHost flushes any receiver that wasn't processed. This avoids double-emitting raw pointer events when the system is present while preventing the leak when it is absent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
===:clipboard: PR Checklist :clipboard:===
==================
Closes #3356
Changes:
PointerEventReceiveraccumulates native pointer events in itscurrentFrameDown/currentFrameUp/currentFrameMove/currentFrameCancel/currentFrameWheelarrays. Those arrays were only ever consumed (update()) and freed (clear()) byPointerSystem.update()each frame. If a scene removes thePointerSystem(e.g.world.remove(world.get(PointerSystem))), nothing flushes those arrays, so they grow without bound on every native pointer event — a memory leak (as noted by @eonarheim, pointer flushing should not depend on the system being present).src/engine/input/input-host.ts:InputHost.update()(which runs every frame for both the engine-level and scene-level input hosts) now guarantees the pointer receiver is flushed exactly once per frame, independent of thePointerSystem. If the receiver was already processed by the system this frame, it just resets the marker; otherwise it callsupdate()+clear()itself.src/engine/input/pointer-system.ts: after the system updates/clears each receiver it marksreceiver._processedThisFrame = trueso theInputHostfallback does not double-process (and therefore never double-emits raw pointer events) when aPointerSystemis active.src/engine/input/pointer-event-receiver.ts: added the internal_processedThisFrameflag used to coordinate the two.src/spec/vitest/pointer-input-spec.ts: added a regression test that removes thePointerSystemfrom the scene, dispatches several pointer events across multiple frames, and asserts the receiver'scurrentFrame*arrays stay empty.CHANGELOG.md: added a Fixed entry.