Skip to content

Commit 8e99389

Browse files
committed
Make sure we flush commands before destroying textures
1 parent 606b135 commit 8e99389

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/core/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ class p5 {
272272
if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
273273
this._updateAccsOutput();
274274
}
275+
this._renderer.finishSetup?.();
275276

276277
// Run `postsetup` hooks
277278
await this._runLifecycleHook('postsetup');

src/webgpu/p5.RendererWebGPU.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function rendererWebGPU(p5, fn) {
164164

165165
_updateSize() {
166166
if (this.depthTexture && this.depthTexture.destroy) {
167+
this.flushDraw();
167168
this.depthTexture.destroy();
168169
this.depthTextureView = null;
169170
}
@@ -886,8 +887,17 @@ function rendererWebGPU(p5, fn) {
886887
this._pendingCommandEncoders.push(commandEncoder.finish());
887888
this._hasPendingDraws = true;
888889

890+
// Save current transformation state
891+
const savedModelMatrix = this.states.uModelMatrix.copy();
892+
893+
// Copy current camera state to framebuffer's camera
894+
this.mainFramebuffer.defaultCamera.set(this.states.curCamera);
895+
889896
// Activate mainFramebuffer for subsequent draws
890897
this.mainFramebuffer.begin();
898+
899+
// Restore transformation state
900+
this.states.uModelMatrix.set(savedModelMatrix);
891901
}
892902

893903
//////////////////////////////////////////////
@@ -1048,7 +1058,7 @@ function rendererWebGPU(p5, fn) {
10481058
// Only submit if we actually had any draws
10491059
if (this._hasPendingDraws) {
10501060
// Create a copy of pending command encoders
1051-
const commandsToSubmit = this._pendingCommandEncoders.slice();
1061+
const commandsToSubmit = this._pendingCommandEncoders;
10521062
this._pendingCommandEncoders = [];
10531063
this._hasPendingDraws = false;
10541064

@@ -1083,6 +1093,10 @@ function rendererWebGPU(p5, fn) {
10831093
this.flushDraw();
10841094
}
10851095

1096+
finishSetup() {
1097+
this.flushDraw();
1098+
}
1099+
10861100
async finishDraw() {
10871101
this.flushDraw();
10881102

0 commit comments

Comments
 (0)