fix(screen-adapter): debounce resize handler to prevent black flicker on web#19186
Open
UC-RX0 wants to merge 1 commit into
Open
fix(screen-adapter): debounce resize handler to prevent black flicker on web#19186UC-RX0 wants to merge 1 commit into
UC-RX0 wants to merge 1 commit into
Conversation
|
Too many files changed for review. ( |
… on web The window resize event listener was calling _updateFrame() synchronously on every resize event. During continuous window dragging, this triggered dozens of swapchain/backbuffer reallocations per second, each producing a blank frame. This change: - Adds _resizeTimeoutId field for debounce state tracking - Debounces the resize handler using setTimeout with EVENT_TIMEOUT (200ms) - Uncomments and enables the handleResizeEvent guard on the resize path - Adds handleResizeEvent guard to the DPR matchMedia listener, which was previously bypassing it Fixes: cocos#19182
b09bab9 to
cb29d19
Compare
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Code Size Check Report
Interface Check ReportThis pull request does not change any public interfaces ! |
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.
Problem
On Web builds, continuously resizing the browser window produces rapid black flickering. Each
resizeevent synchronously calls_resizeFrame()→_updateContainer()→emit('window-resize'), which triggers a swapchain/backbuffer reallocation. During a continuous drag this fires dozens of times per second, each producing a blank (black) frame before the next render.The same continuous-resize test does not flicker in Cocos Creator 2.x (because v2 keeps a fixed backbuffer and CSS-scales it rather than reallocating on every resize).
Root Cause
In
pal/screen-adapter/src/web/screen-adapter.ts, theresizeevent handler (line 380) had no debounce, unlike theorientationchangehandler (line 407) which already usesEVENT_TIMEOUT(200ms) +setTimeout.Additionally, the DPR
matchMediachange listener (line 397) emittedwindow-resizedirectly, bypassing:handleResizeEventguard (used byview.resizeWithBrowserSize(false))Fix
Debounce the resize handler — Added a
_resizeTimeoutIdfield and debounce logic using the sameEVENT_TIMEOUT(200ms) pattern already used by the orientation change handler. Rapid resize events cancel the pending timeout and restart it; only the last event after the drag stops triggers_resizeFrame().Gate DPR matchMedia handler — Added
handleResizeEventcheck before emittingwindow-resize, consistent with the resize and orientation handlers.Changes
pal/screen-adapter/src/web/screen-adapter.ts: +11/-1 lines_resizeTimeoutIdprivate field_resizeFrame()call insidesetTimeout/clearTimeoutdebouncehandleResizeEventguard to DPR matchMedia listenerSide Effects
_resizeFrame()→_updateContainer()edit-box-impl.ts(temporarily disables handleResizeEvent)view.resizeWithBrowserSize(false)Fixes: #19182
Changelog