Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with removing mesh #2621

Closed
MKHenson opened this issue Nov 11, 2012 · 2 comments
Closed

Problem with removing mesh #2621

MKHenson opened this issue Nov 11, 2012 · 2 comments
Labels

Comments

@MKHenson
Copy link

Hi guys

I am using the dev branch of the code, and have recently run into a problem. In my scene I have a grid and I'm loading a Mesh in. In the app the user can then choose to load a different mesh and so therefore I need to completely remove the existing one from the scene. The problem is that when I do this, it removes the plane geometry as well and the browser throws a few webgl errors.

I re-created the problem in the example file webgl_test_memory.html file.

Simply add these lines to the end of the 'init' function:

var planeMaterial = new THREE.MeshBasicMaterial( { color: 0x444444, wireframe: true } );

//Add a grid to the viewort
var plane = new THREE.Mesh( new THREE.PlaneGeometry( 30, 30, 30, 30 ), planeMaterial );
plane.rotation.x = - Math.PI / 2;
scene.add( plane );

Is this a bug or am I missing something here?

Also, can I just ask for some clarification on what these functions do...

mesh.deallocate();
mesh.geometry.deallocate();
mesh.material.deallocate();

renderer.deallocateObject( mesh );
renderer.deallocateTexture( texture );

Does the deallocate function simply subtract a memory reference and then the deallocateObject and deallocateTexture actually remove it?

Thanks guys

@MKHenson
Copy link
Author

Bug related to #2633

Just in case anyone is interested - the deallocate methods are indeed used for reference counting. They keep track of all the Three JS objects created in the scene. Each object type has its own array and its important to remove the reference so that there are no dangling pointers.

Just closing this issue.

@MKHenson
Copy link
Author

Excellent! That did the trick. I haven't noticed any immediate performance hits, but I will let you know if I find anything else :)

Cheers guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant