Skip to content

fix(captures): serialize webgl requests to prevent memory leak when doing bulk captures and always clean up#37

Open
jnccloud wants to merge 3 commits into
itschip:mainfrom
geocityrp:main
Open

fix(captures): serialize webgl requests to prevent memory leak when doing bulk captures and always clean up#37
jnccloud wants to merge 3 commits into
itschip:mainfrom
geocityrp:main

Conversation

@jnccloud

Copy link
Copy Markdown

chromium by default only has 16 contexts and is supposed to handle it on its own, but I was running into frequent issues (out of game memory) and sluggish behavior during bulk capture sessions (aka green screens). this maintained my capture rate at about 1 per second for clothing items and I no longer suffered from out of game memory errors.

@itschip

itschip commented May 8, 2026

Copy link
Copy Markdown
Owner

Hi @jnccloud , thanks for the PR! Looks good! Could you please rebase your branch to the lastest upstream changes and then remove the fxmanifest change. No need to manually update the version

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to improve stability during bulk screenshot capture by serializing capture requests (avoiding overlapping WebGL context usage) and ensuring capture resources are cleaned up more reliably to prevent memory/context leaks.

Changes:

  • Serialize incoming capture messages via an internal promise queue to prevent concurrent WebGL captures.
  • Add try/finally cleanup in captureScreen() so dispose()/DOM cleanup runs even when capture/upload fails.
  • Bump resource version to 0.13.0-beta.2.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
game/nui/src/capture.ts Adds a capture queue and a try/finally cleanup path to reduce WebGL-context/memory issues during bulk capture.
fxmanifest.lua Updates the resource version to 0.13.0-beta.2 (and minor formatting).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread game/nui/src/capture.ts
Comment on lines +97 to +102
} finally {
this.#gameView.dispose();
this.#canvas.remove();
this.#gameView = null;
this.#canvas = null;
}
Comment thread game/nui/src/capture.ts
Comment on lines 77 to +81
this.#gameView = createGameView(this.#canvas);
this.#gameView.resize(width, height);

// Wait for the FiveM WebGL hook to populate the game framebuffer
await this.waitForFrames(3);
try {
// Wait for the FiveM WebGL hook to populate the game framebuffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants