aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-06-25 13:43:27 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-06-25 13:43:27 -0700
commita73bd3ee5f76a5cd460732f037112be285e1dbab (patch)
treedb1fb1fcab8fef7f0d8e137480a64c845d712914
parent857c94f2709ef0c3b37574174e466955b8a6cdd7 (diff)
clone ArrayBuffers properly in proxying code
-rw-r--r--src/webGLWorker.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/webGLWorker.js b/src/webGLWorker.js
index a04293e7..4620fd43 100644
--- a/src/webGLWorker.js
+++ b/src/webGLWorker.js
@@ -714,13 +714,17 @@ function WebGLWorker() {
}
}
};
+ function duplicate(something) {
+ // clone data properly: handles numbers, null, typed arrays, js arrays and array buffers
+ if (!something || typeof something === 'number') return something;
+ if (something.slice) return something.slice(0); // ArrayBuffer or js array
+ return new something.constructor(something); // typed array
+ }
this.bufferData = function(target, something, usage) {
- if (typeof something !== 'number') something = new something.constructor(something);
- commandBuffer.push(27, target, something, usage);
+ commandBuffer.push(27, target, duplicate(something), usage);
};
this.bufferSubData = function(target, offset, something) {
- if (typeof something !== 'number') something = new something.constructor(something);
- commandBuffer.push(28, target, offset, something);
+ commandBuffer.push(28, target, offset, duplicate(something));
};
this.viewport = function(x, y, w, h) {
commandBuffer.push(29, x, y, w, h);
@@ -773,10 +777,10 @@ function WebGLWorker() {
};
this.texImage2D = function(target, level, internalformat, width, height, border, format, type, pixels) {
assert(pixels || pixels === null); // we do not support the overloads that have fewer params
- commandBuffer.push(40, target, level, internalformat, width, height, border, format, type, pixels ? new pixels.constructor(pixels) : pixels);
+ commandBuffer.push(40, target, level, internalformat, width, height, border, format, type, duplicate(pixels));
};
this.compressedTexImage2D = function(target, level, internalformat, width, height, border, pixels) {
- commandBuffer.push(41, target, level, internalformat, width, height, border, new pixels.constructor(pixels));
+ commandBuffer.push(41, target, level, internalformat, width, height, border, duplicate(pixels));
};
this.activeTexture = function(texture) {
commandBuffer.push(42, texture);