0 votes

Hi,
I'm working on editor plugin. The important code does this: Each time the user clicks on MeshInstance, new Mesh is generated by SurfaceTool and it's set in MeshInstance.set_mesh(). The old resource is no longer in use and should be freed by engine. Quick look at Task Manager showed me that every time I click, 20-80 kB of data is allocated.

I'm sure the MeshInstance.set_mesh() is leaking because if I just generate new mesh and don't set it, no memory is leaking. Is there a way to force old mesh resource to free?

Important part of the code:

var newWireMesh = generateWireframeMesh(meshTool)
meshInstance.get_meta("orgMesh").surface_remove(0)
meshTool.commit_to_surface(meshInstance.get_meta("orgMesh"))
meshInstance.get_mesh().surface_remove(0)
meshInstance.set_mesh(newWireMesh)

The whole script is on Pastebin

in Engine by (820 points)

I fixed the leak. If you do something similar as me, a good practice is to reuse the Mesh. You can pass the old mesh to SurfaceTool.commit(oldMesh). It will create a new surface with your new data. Don't forget to delete your old surface first: oldMesh.surface_remove(0). It's only a bypass tho. The leak is still imminent.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.