p5.js
p5.js copied to clipboard
Calling loadModel while a custom shader is in use breaks the existing shader.
Most appropriate sub-area of p5.js?
- [ ] Accessibility (Web Accessibility)
- [ ] Build tools and processes
- [ ] Color
- [ ] Core/Environment/Rendering
- [ ] Data
- [ ] DOM
- [ ] Events
- [ ] Friendly error system
- [ ] Image
- [ ] IO (Input/Output)
- [ ] Localization
- [ ] Math
- [ ] Unit Testing
- [ ] Typography
- [ ] Utilities
- [X] WebGL
- [ ] Other (specify if possible)
Details about the bug:
- p5.js version: 1.4.0
- Web browser and version: Chromium: 94.0.4606.71 & Firefox 93.0
- Operating System: MacOS 10.15.7
- Steps to reproduce this:
- Load a model
- Load a shader
- Draw the model with the shader
- Load another model
- Try to draw anything with the existing shader
The root cause is that calls to loadModel()
outside of preload()
are causing setup()
to get called a second time. This should not happen! There is something wrong with the preload wrapper function for some if not all load***
calls (specifically it is looking for _setupDone
in the wrong place (or _setupDone
is being set to true in the wrong place) for sketches in global mode
let model1;
let model2;
let shader1;
function preload() {
model1 = loadModel("teapot.obj", true);
shader1 = loadShader("shader.vert", "shader.frag");
}
let i = 0;
function setup() {
console.log(`setup called ${i++}`);
createCanvas(windowWidth, windowHeight, WEBGL);
noLoop();
noStroke();
background(255);
scale(1, -1, 1);
shader(shader1);
model(model1);
}
function doubleClicked() {
if (!model2) {
model2 = loadModel("gourd.obj", false, () => {
console.log("loaded");
background("green");
// broken!
model(model1);
});
}
}
https://editor.p5js.org/Kumu-Paul/sketches/rmpqtMN-X