Skip to content

Commit

Permalink
Merge pull request #664 from stopyoukid/fix/pipeline-texture-crash
Browse files Browse the repository at this point in the history
fix: crash when using a pipeline kernel + constant texture
  • Loading branch information
robertleeplummerjr authored Jan 19, 2021
2 parents 8634a6c + 40a83ec commit 22604e9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class WebGLKernelValueMemoryOptimizedNumberTexture extends WebGLKernelArray {
if (kernel.immutable) {
kernel.updateTextureArgumentRefs(this, inputTexture);
} else {
if (kernel.texture.texture === inputTexture.texture) {
if (kernel.texture && kernel.texture.texture === inputTexture.texture) {
throw new Error(sameError);
} else if (kernel.mappedTextures) {
const { mappedTextures } = kernel;
Expand All @@ -69,4 +69,4 @@ class WebGLKernelValueMemoryOptimizedNumberTexture extends WebGLKernelArray {
module.exports = {
WebGLKernelValueMemoryOptimizedNumberTexture,
sameError
};
};
4 changes: 2 additions & 2 deletions src/backend/web-gl/kernel-value/number-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WebGLKernelValueNumberTexture extends WebGLKernelArray {
if (kernel.immutable) {
kernel.updateTextureArgumentRefs(this, inputTexture);
} else {
if (kernel.texture.texture === inputTexture.texture) {
if (kernel.texture && kernel.texture.texture === inputTexture.texture) {
throw new Error(sameError);
} else if (kernel.mappedTextures) {
const { mappedTextures } = kernel;
Expand All @@ -70,4 +70,4 @@ class WebGLKernelValueNumberTexture extends WebGLKernelArray {

module.exports = {
WebGLKernelValueNumberTexture
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,38 @@ test('.constructor() checks ok height & width', () => {
});
assert.equal(v.constructor.name, 'WebGLKernelValueMemoryOptimizedNumberTexture');
});

test('.updateValue() should set uploadValue when a pipeline kernel has no texture', () => {
const mockKernel = {
constructor: {
features: { maxTextureSize: 2 },
},
validate: true,
pipeline: true,
setUniform3iv: () => {},
setUniform2iv: () => {},
setUniform1i: () => {},
};
const mockContext = {
activeTexture: () => {},
bindTexture: () => {},
texParameteri: () => {},
pixelStorei: () => {},
texImage2D: () => {},
};
const v = new webGLKernelValueMaps.unsigned.static.MemoryOptimizedNumberTexture({ size: [2,2], context: mockContext }, {
kernel: mockKernel,
name: 'test',
type: 'MemoryOptimizedNumberTexture',
origin: 'user',
tactic: 'speed',
context: mockContext,
onRequestContextHandle: () => 1,
onRequestTexture: () => null,
onRequestIndex: () => 1
});

const newMockTexture = {}
v.updateValue({ size: [2,2], context: mockContext, texture: newMockTexture })
assert.equal(v.uploadValue, newMockTexture)
});
35 changes: 35 additions & 0 deletions test/internal/backend/web-gl/kernel-value/number-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,38 @@ test('.constructor() checks ok height & width', () => {
});
assert.equal(v.constructor.name, 'WebGLKernelValueNumberTexture');
});

test('.updateValue() should set uploadValue when a pipeline kernel has no texture', () => {
const mockKernel = {
constructor: {
features: { maxTextureSize: 2 },
},
pipeline: true,
validate: true,
setUniform3iv: () => {},
setUniform2iv: () => {},
setUniform1i: () => {},
};
const mockContext = {
activeTexture: () => {},
bindTexture: () => {},
texParameteri: () => {},
pixelStorei: () => {},
texImage2D: () => {},
};
const v = new webGLKernelValueMaps.unsigned.static.NumberTexture({ size: [2,2], context: mockContext }, {
kernel: mockKernel,
name: 'test',
type: 'NumberTexture',
origin: 'user',
tactic: 'speed',
context: mockContext,
onRequestContextHandle: () => 1,
onRequestTexture: () => null,
onRequestIndex: () => 1
});

const newMockTexture = {}
v.updateValue({ size: [2,2], context: mockContext, texture: newMockTexture })
assert.equal(v.uploadValue, newMockTexture)
});

0 comments on commit 22604e9

Please sign in to comment.