From 9bf891dce4754c34f8bae5091d23eb35e724591c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 26 Mar 2026 06:49:27 +0000 Subject: [PATCH] ensure unconditional data write for all GPU buffer cells Refactored `packPatternMatrix` in `hooks/useGPUBuffers.ts` to ensure that both packed words for every pattern cell are unconditionally assigned. Previously, the second word was only written if the cell did not contain text or if it was explicitly parsed, potentially leaving uninitialized values in the buffer for certain edge cases (e.g. whitespace-only text). Verified that `packPatternMatrixHighPrecision` already follows the correct pattern. Co-authored-by: ford442 <9397845+ford442@users.noreply.github.com> --- mod-player-shaders/hooks/useGPUBuffers.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mod-player-shaders/hooks/useGPUBuffers.ts b/mod-player-shaders/hooks/useGPUBuffers.ts index 7524fd6..35cc69a 100644 --- a/mod-player-shaders/hooks/useGPUBuffers.ts +++ b/mod-player-shaders/hooks/useGPUBuffers.ts @@ -104,6 +104,7 @@ export const packPatternMatrix = (matrix: PatternMatrix | null, padTopChannel = let volVal = 0; let effCmd = 0; let effVal = 0; + let wordB = 0; if (cell) { // First try numeric fields (from getPatternMatrix) @@ -114,6 +115,7 @@ export const packPatternMatrix = (matrix: PatternMatrix | null, padTopChannel = volVal = cell.volVal || 0; effCmd = cell.effCmd || 0; effVal = cell.effVal || 0; + wordB = ((effCmd & 0xFF) << 8) | (effVal & 0xFF); } // Fall back to parsing text if available else if (cell.text && cell.text.trim()) { @@ -123,15 +125,13 @@ export const packPatternMatrix = (matrix: PatternMatrix | null, padTopChannel = const instMatch = text.match(/(\d{1,3})$/); inst = instMatch?.[1] ? Math.min(255, parseInt(instMatch[1], 10)) : 0; note = encodeNoteText(notePart); - packed[offset + 1] = parsePackedB(text) >>> 0; + wordB = parsePackedB(text) >>> 0; } } // Always write packed data for this cell position packed[offset] = ((note & 0xFF) << 24) | ((inst & 0xFF) << 16) | ((volCmd & 0xFF) << 8) | (volVal & 0xFF); - if (!cell?.text) { - packed[offset + 1] = ((effCmd & 0xFF) << 8) | (effVal & 0xFF); - } + packed[offset + 1] = wordB; } } return packed;