From ad2b7e53affeaf04cfbc2453b245b645ccf89602 Mon Sep 17 00:00:00 2001 From: Rezmason Date: Thu, 28 Oct 2021 23:56:31 -0700 Subject: [PATCH] buildStruct needs to convert values into arrays --- js/webgpu_main.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/js/webgpu_main.js b/js/webgpu_main.js index f3875cd..e22fb37 100644 --- a/js/webgpu_main.js +++ b/js/webgpu_main.js @@ -81,8 +81,17 @@ const buildStruct = (layout, values) => { if (diff > 0) { buffer.push(Array(diff).fill()); } - buffer.push(values[i]); - count += values[i].length + diff; + const value = values[i]; + let array; + if (Array.isArray(value)) { + array = value; + } else if (value[Symbol.iterator] != null) { + array = Array.from(value); + } else { + array = [value]; + } + buffer.push(array); + count += array.length + diff; } { const diff = sizeInBytes - count;