You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I meet a strange issue when trying to delete a BufferGeometry. I remove it from my scene then call dispose() on the texture, material, and geometry.
This works fine as long as I have s single scene with a perspective camera and only Geometries.
But if I render a second scene with an orthographic camera and a Sprite, the Sprite rendering fails if I delete a Mesh geometry, with a GL error
Error: WebGL: drawElements: no VBO bound to enabled vertex attrib index 2!
I've written a small reproduction for the problem (code below, needs only the threejs sdk). Wait about 5 seconds and it deletes the Mesh, and this will result in a failure when rendering the Sprite.
If I comment the rendering of the background scene, no error.
<!DOCTYPE html><htmllang="en"><head><title>three.js webgl - geometries</title><metacharset="utf-8"><metaname="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"><style>
body {
font-family: Monospace;
background-color: #000;
margin: 0px;
overflow: hidden;
}
</style></head><body><scriptsrc="build/three.min.js"></script><scriptsrc="js/Detector.js"></script><scriptsrc="js/libs/stats.min.js"></script><script>if(!Detector.webgl)Detector.addGetWebGLMessage();varcontainer,stats;varcamera,scene,renderer;frame_count=0;init();animate();functioninit(){container=document.createElement('div');document.body.appendChild(container);camera=newTHREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,2000);camera.position.y=400;// I need a second camera for my 2D sprite (used as a background)// must use another texture so that it's not destroyed when removing the first objectcameraOrtho=newTHREE.OrthographicCamera(window.innerWidth/-2,window.innerWidth/2,window.innerHeight/2,window.innerHeight/-2,1,10);cameraOrtho.position.z=10;cameraOrtho.position.y=400;sceneBackground=newTHREE.Scene();varmap1=THREE.ImageUtils.loadTexture('textures/disturb.jpg');varmaterial1=newTHREE.SpriteMaterial({map: map1});varspriteBackground=newTHREE.Sprite(material1);spriteBackground.scale.set(window.innerWidth,window.innerHeight,1);spriteBackground.position.set(window.innerWidth/2,window.innerHeight/2);sceneBackground.add(spriteBackground);scene=newTHREE.Scene();varlight;my_object=null;scene.add(newTHREE.AmbientLight(0x404040));light=newTHREE.DirectionalLight(0xffffff);light.position.set(0,1,0);scene.add(light);varmap=THREE.ImageUtils.loadTexture('textures/UV_Grid_Sm.jpg');map.wrapS=map.wrapT=THREE.RepeatWrapping;map.anisotropy=16;varmaterial=newTHREE.MeshLambertMaterial({map: map,side: THREE.DoubleSide});// one object is enough to demonstrate// can't reproduce the problem with a standard SphereGeometry// try to convert it to a BufferGeometryvarsphereGeometry=newTHREE.SphereGeometry(75,20,10);varbufferGeometry=newTHREE.BufferGeometry().fromGeometry(sphereGeometry);my_object=newTHREE.Mesh(bufferGeometry,material);my_object.position.set(-400,0,200);scene.add(my_object);renderer=newTHREE.WebGLRenderer({antialias: true});renderer.setPixelRatio(window.devicePixelRatio);renderer.setSize(window.innerWidth,window.innerHeight);renderer.autoClear=false;renderer.autoClearDepth=false;container.appendChild(renderer.domElement);stats=newStats();stats.domElement.style.position='absolute';stats.domElement.style.top='0px';container.appendChild(stats.domElement);window.addEventListener('resize',onWindowResize,false);}functiononWindowResize(){camera.aspect=window.innerWidth/window.innerHeight;camera.updateProjectionMatrix();renderer.setSize(window.innerWidth,window.innerHeight);}//functionanimate(){requestAnimationFrame(animate);render();stats.update();}functionrender(){frame_count++;vartimer=Date.now()*0.0001;camera.position.x=Math.cos(timer)*800;camera.position.z=Math.sin(timer)*800;camera.lookAt(scene.position);//after a few frames I want to destroy completely the object//means remove from the scene, remove texture, material, geometry//note that here it's a Geometry, not a BufferGeometry//may be differentif(frame_count>60*5){if(my_object!=null){console.log("destroy object buffer");scene.remove(my_object);my_object.material.map.dispose();my_object.material.dispose();my_object.geometry.dispose();my_object=null;}}for(vari=0,l=scene.children.length;i<l;i++){varobject=scene.children[i];object.rotation.x=timer*5;object.rotation.y=timer*2.5;}renderer.render(sceneBackground,cameraOrtho);renderer.clearDepth();renderer.render(scene,camera);}</script></body></html>
The text was updated successfully, but these errors were encountered:
The build directory for the dev branch in git has not been updated in a while and does not include the fix. You should run the build command (instructions on the wiki) in your local copy. I'm confident that it will work :)
Now that the build has been updated on the dev branch, I've created a fiddle with the original submission using a CDN do demonstrate that the issue is resolved:
Hi,
I meet a strange issue when trying to delete a BufferGeometry. I remove it from my scene then call dispose() on the texture, material, and geometry.
This works fine as long as I have s single scene with a perspective camera and only Geometries.
But if I render a second scene with an orthographic camera and a Sprite, the Sprite rendering fails if I delete a Mesh geometry, with a GL error
Error: WebGL: drawElements: no VBO bound to enabled vertex attrib index 2!
I've written a small reproduction for the problem (code below, needs only the threejs sdk). Wait about 5 seconds and it deletes the Mesh, and this will result in a failure when rendering the Sprite.
If I comment the rendering of the background scene, no error.
The text was updated successfully, but these errors were encountered: