Dispose Texture Does Not Work
omaralcheikh opened this issue · comments
Hello Cristi,
It seems that the dispose function on textures is conflicting with dom.js. I am getting the following error:
TypeError: Object doesn't support property or method 'deleteTexture'
at deallocateTexture (three.js:18151:17)
at onTextureDispose (three.js:18109:13)
at dispatchEvent (three.js:179:21)
at dispose (three.js:3828:13)
at Anonymous function (basic-cube.js:42:17)
at Anonymous function (three.js:30847:21)
at Anonymous function (three.js:30690:29)
at invoke (dom.js:9151:25)
at _dispatchEvent (dom.js:9190:17)
at dispatchEvent (dom.js:9079:13)
This is causing the memory to keep increasing due to the stacked textures. I altered the basic cube example to test it:
function BasicCubeExample(scene, renderer) {
this.scene = scene;
this.renderer = renderer;
let ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.8);
scene.add(ambientLight);
let loader = new THREE.TextureLoader();
let material = new THREE.MeshStandardMaterial({ vertexColors: THREE.VertexColors, map: new THREE.DataTexture(new Uint8Array(3).fill(255), 1, 1, THREE.RGBFormat) });
var i = 0;
let cube = new THREE.Mesh(new THREE.BoxBufferGeometry(0.2, 0.2, 0.2), material.clone());
setInterval(function () {
if (cube.material.map !== null)
cube.material.map.dispose();
cube.material.dispose();
scene.remove(cube);
cube.geometry.dispose();
cube.geometry.dispose();
loader.setCrossOrigin('anonymous');
material.map.needsUpdate = true;
cube.position.set(i, 0, 0);
i += 0.01;
cube.geometry.addAttribute('color', new THREE.BufferAttribute(Float32Array.from([
1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, // right - red
0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, // left - blue
0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, // top - green
1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, // bottom - yellow
0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, // back - cyan
1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0 // front - purple
]), 3));
loader.load('texture.png', tex => {
if (cube.material.map !== null)
cube.material.map.dispose();
cube.material.map = tex;
});
scene.add(cube);
}, 1000)
this.update = function (delta, elapsed) {
};
}
deleteTexture was not implemented. The fix is merged into master.