Repository navigation
fix(nui-core): release game-view compat renderers when their canvas is removed - #4351
Open
BingoWings247 wants to merge 1 commit into
Open
BingoWings247 wants to merge 1 commit into
BingoWings247 wants to merge 1 commit into
Conversation
Author
|
The Windows build failures are from the CI runner, not this change: |
…s removed. The x-cfx-game-view compat renderer's only teardown listened for a 'remove' event, which is not a DOM event, so every mounted game view kept a full-frame WebGL2 render loop running after its element was removed. destroy() also referenced an undefined `canvas`, so it threw before releasing the WebGL context whenever the canvas still had a parent. Track compat canvases with a live renderer and, from the existing MutationObserver, run the existing teardown for any that left the document (after a 1s grace so moved or briefly detached canvases keep their renderer). Fix destroy() to remove this.#canvas. Signed-off-by: BingoWings247 <hilldavid71150@gmail.com>
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.
Goal of this PR
Fix two defects in the
application/x-cfx-game-viewcompatibility renderer (EpoxyScript.h) that keep a full-frame WebGL2 renderer running for every game-view element a page has ever mounted (#4342):canvas.addEventListener('remove', ...).removeis not a DOM event, so it never fires when a page removes the element; therequestAnimationFrameloop and the WebGL2 context (powerPreference: 'high-performance') stay alive.CfxGameViewRenderer.destroy()callsthis.#canvas.parentNode.removeChild(canvas), wherecanvasis not defined in that scope. Whenever the canvas still has a parent (including a container that was itself detached),destroy()throwsReferenceError: canvas is not definedafter cancelling the rAF loop but beforeWEBGL_lose_context, so the context is never released and the listener never reachesresizeObserver.disconnect(). This also breaks resources that work around (1) by dispatchingremovethemselves.How is this PR achieving the goal
destroy():removeChild(canvas)→removeChild(this.#canvas).LiveCanvases). The existingMutationObserver, which already watches the whole document, checks them on each mutation batch. A canvas that is no longerisConnectedgets a 1 second grace period, so moving it between containers or briefly detaching it keeps its renderer; after that the existing teardown runs by dispatching theremoveevent the listener was already waiting for. The listener is now{ once: true }and removes the canvas from the set.new CfxGameViewRenderer(canvas)are unaffected (their owner callsdestroy()), and resources that already dispatchremovekeep working.Before/after, using the
g_gameViewScriptextracted from master 88a4138 and injected into a page the way NUI does:removewhile the canvas is attachedReferenceError: canvas is not defined, context stays aliveThis PR applies to the following area(s)
FiveM, RedM
Successfully tested on
Game builds: n/a. The change is JavaScript inside the
g_gameViewScriptraw string literal; I verified the literal still terminates in the same place and the extracted script parses.Platforms: Headless Chromium (ANGLE). Not built in a client locally; CI will compile it.
Checklist
Fixes issues
fixes #4342