Skip to content

Commit

Permalink
[Fix] Make sure texture units are initialized (#5744)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky authored Oct 11, 2023
1 parent ec72104 commit 342dd37
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/platform/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ class WebglGraphicsDevice extends GraphicsDevice {

this.updateClientRect();

// initialize this before registering lost context handlers to avoid undefined access when the device is created lost.
this.initTextureUnits();

// Add handlers for when the WebGL context is lost or restored
this.contextLost = false;

Expand Down Expand Up @@ -1137,6 +1140,13 @@ class WebglGraphicsDevice extends GraphicsDevice {
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
}

initTextureUnits(count = 16) {
this.textureUnits = [];
for (let i = 0; i < count; i++) {
this.textureUnits.push([null, null, null]);
}
}

initializeContextCaches() {
super.initializeContextCaches();

Expand All @@ -1149,10 +1159,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
this.transformFeedbackBuffer = null;

this.textureUnit = 0;
this.textureUnits = [];
for (let i = 0; i < this.maxCombinedTextures; i++) {
this.textureUnits.push([null, null, null]);
}
this.initTextureUnits(this.maxCombinedTextures);
}

/**
Expand Down

0 comments on commit 342dd37

Please sign in to comment.