FreeEntity

Started by JBR, February 22, 2020, 19:13:44

Previous topic - Next topic

JBR

I understand we should FreeEntity entity, but what about Pivots when done with them?

Jim

angros47

You should free them as well. Otherwise, the library will still check on them each time commands like UpdateWorld or RenderWorld are invoked, so they will slow down elaboration (minimally, but if you have hundreds, or thousands of unused pivots they can impact performance). Most important, they will keep using a small amount of memory, so creating pivots and not freeing them would result in potential memory leaks (that are hard to debug, and cause random crashes)

JBR

#2
Trying to remove the pivot stalls my pc. It works fine without removing the pivot. ???

Function Line:TEntity(x1#,y1#,z1#,x2#,y2#,z2#)

Local scale# = G_Line_Scale

Local c1:TEntity=CreateSphere()
PositionEntity c1,x1,y1,z1

Local c2:TEntity=CreateSphere()
PositionEntity c2,x2,y2,z2

Local p:TPivot=CreatePivot()
PositionEntity p,x1,y1,z1

Local le#=EntityDistance# (c1,c2) / 2.0
'le#=le#-(le#/2)

Local c3:TEntity=CreateCylinder()
PositionEntity c3,x1,le+y1,z1

ScaleEntity c3,scale,le,scale
EntityColor c3,255,255,255

EntityParent c3,p

PointEntity p,c2
TurnEntity p,90,0,0

FreeEntity c1
FreeEntity c2
FreeEntity p

Return(c3)

End Function

angros47

Freeing an entity destroys its children, as well, so it destroys c3. You should not free the pivot, and you should return the pivot instead of the entity c3. Or you should "unparent" c3 before freeing the pivot

JBR

Can't find a way to unparent the pivot.

jim

Matty

Set the parent to 0 should unparent it from memory.

angros47

Otherwise, when you will have to remove the entity c3, instead of freeing it, you get its parent with GetParent, and then you free the parent