Skip to content

Fix CEF browser handling during screenshots#5040

Open
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-cef-browser-screenshots
Open

Fix CEF browser handling during screenshots#5040
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-cef-browser-screenshots

Conversation

@HeresHavi

@HeresHavi HeresHavi commented Jul 12, 2026

Copy link
Copy Markdown

Summary

Restored CEF browser textures immediately after takePlayerScreenShot using their retained frame.
Screenshot restoration now also skips browser views that have not finished asynchronous CEF creation.

Browser content remains excluded from uploaded screenshots.

Motivation

MTA clears browser textures before capturing an uploaded screenshot. The old restoration path only requested an asynchronous CEF repaint afterward, which left the cleared white texture visible to the player for a rendered frame.

The restoration path also assumed every web view already had a CEF browser. Browser creation is asynchronous, so a screenshot could reach this path while GetCefBrowser() was still null.

For example, a server may use takePlayerScreenShot while the player has a browser-based chat or HUD. The browser could briefly flash white, or the restoration path could encounter a browser that was still being created.

Addresses the confirmed browser flicker reported in #4521.

Confirmed Reproduction
  • A full-screen local browser was continuously rendered with dxDrawImage.
  • The server requested screenshots with takePlayerScreenShot.
  • Frame-by-frame inspection captured the browser region as a solid white rectangle before the fix.
  • A queued screenshot-before-browser test reached OnPostScreenshot while GetCefBrowser() was null in 1 of 20 attempts.
  • A temporary diagnostic guard caught that null state before the original dereference.

Issue #4521 also reports a later libcef.dll client failure. That failure was not reproduced during the screenshot and resource-restart tests, so this PR does not claim a matching crash stack for it.

Test plan

Runtime

  • Before Fix: Taking a screenshot while rendering a browser produced a solid white browser frame. A queued screenshot also reached the restoration path while the CEF browser was still null.
  • After Fix: Completed 20 screenshot attempts without a white frame and 50 queued browser-initialization attempts without instability.
  • Valid Case: Completed 20 screenshot and genuine resource-restart cycles. Every recreated browser reached document-ready state, and uploaded screenshots continued to exclude browser content.
  • Issue Check: Repeated the full-screen browser setup from takePlayerScreenShot causes DX-based browser elements to flicker and crash client (libcef.dll) #4521 with 20 screenshots before and 20 after a resource restart. The browser remained stable without white flashes.

Builds and Tests

  • Debug | Win32: Client Webbrowser build passed.
  • Release | Win32: Client Webbrowser build passed.
  • Ran clang-format.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

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.

1 participant