iminib3d leaks when copying entity

BlitzMax Forums/MiniB3D Module/iminib3d leaks when copying entity

ima747(Posted 2012) [#1]
I'm doing leak checks and I'm getting quite a few, all from Brush::Copy() and Surface::Surface(). Both 80 bytes. I can't quite figure out what's going sideways...

My app does a large number of entity copies (and freeing of those entities) on meshes so it's probably not something that would usually pop up. I'm not 100% that is a copy entity problem but it very much seems like it.

Any thoughts on where to dig would be much appreciated.


ima747(Posted 2012) [#2]
Definitely a copy problem... using copy mesh or copy entity it leaks. If I create new meshes every time it doesn't leak. I'm not sure CopyEntity gives any render time improvements on iOS over just using dedicated meshes each time, if it doesn't it's not a problem for me I can just create a new mesh each time, but would prefer to do it "right"... just have to stop the leaks...

Update:
mesh->brush=*brush.Copy(); line 97 in mesh.mm causes the brush leak, I assume the surface leak is in the surface area of the copy. Not sure how to work around it...

Update 2:
changing mesh->brush=*brush.Copy(); to mesh->brush = brush; fixes the brush leak and doesn't seem to cause any problems... not sure why it was copying in the first place which concerns me a little...

No luck with surfaces...

Update 3:
AHA! new_surf->brush=surf->brush->Copy(); needs to delete the new_surf->brush before setting the new one (like it does in create surface). Put delete new_surf->brush; right above new_surf->brush=surf->brush->Copy(); and the surface leaks go away... I *think* this is all legit. Would love to get some feedback from simon to confirm I'm not creating a gremlin... the brush copy is the main thing that worries me.

Last edited 2012


simonh(Posted 2012) [#3]
Thanks ima747. Good work digging these out.

Your fixes look fine to me. I was worried that the 'mesh->brush = brush' fix might cause problems with shared pointers, but then I realised the brushes that belong to an entity (and so a mesh) aren't actually pointers, but are actual brush objects. So that fix copies the brush properties from one to the other as it should do.


ima747(Posted 2012) [#4]
Yay, thanks for the insight. Always makes me nervous when I fix stuff by hitting it until the warnings die...