Skip to content

Commit 2acfde1

Browse files
vchelaruclaude
andcommitted
Skip canvas buffer realloc during splitter drag (#105)
Assigning canvas.width/height reallocates the WebGL drawing buffer; on Windows Chrome (ANGLE -> D3D11) a fresh buffer is magenta until drawn. During a splitter drag the holder resizes every frame while the game step may be skipped or lag the resize, so the raw magenta buffer shows through for the whole drag. Guard the per-frame buffer sync in tickJS on !_uiDragging: the last-good buffer stretches via CSS (#theCanvas is 100% of the holder) during the drag, and the first tick after drag-end sees the size mismatch and reallocates once, snapping crisp. Also removes per-frame realloc + OnCanvasResized churn during a drag. Both splitter handlers set _uiDragging, so one guard covers both. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 988edeb commit 2acfde1

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

XnaFiddle.BlazorGL/wwwroot/index.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,20 @@
129129
// Subtract remainder to avoid drift accumulating over time
130130
window._lastTickTime = now - (elapsed % window._tickInterval);
131131
}
132-
// Sync canvas drawing buffer to its container each frame
132+
// Sync canvas drawing buffer to its container each frame — but NOT while a splitter is
133+
// being dragged (issue #105). Assigning canvas.width/height REALLOCATES the WebGL drawing
134+
// buffer, and on Windows Chrome (ANGLE -> D3D11) a fresh buffer is filled with magenta as
135+
// its uninitialized pattern. Normally invisible because the game's Draw repaints it that
136+
// same frame — but a splitter drag changes the holder size every frame while the game step
137+
// may be skipped (touch, _uiDragging) or lag the resize, so the raw magenta buffer shows
138+
// through for the whole drag. Instead we let the last-good buffer stretch via CSS
139+
// (#theCanvas is width/height:100% of the holder) during the drag — slightly soft — and
140+
// reallocate once on drag-end: the first tick after _uiDragging clears sees the size
141+
// mismatch below and snaps the buffer crisp. This also removes the per-frame realloc +
142+
// OnCanvasResized churn during a drag. Both splitter handlers set _uiDragging.
133143
var canvas = document.getElementById('theCanvas');
134144
var holder = document.getElementById('canvasHolder');
135-
if (canvas && holder) {
145+
if (canvas && holder && !window._uiDragging) {
136146
var w = holder.clientWidth;
137147
var h = holder.clientHeight;
138148
if (canvas.width !== w || canvas.height !== h) {

0 commit comments

Comments
 (0)