Ooops
May 26, 2020, 05:49:26 PM

Author Topic: FreeEntity  (Read 395 times)

Offline JBR

  • Jr. Member
  • **
  • Posts: 91
FreeEntity
« on: February 22, 2020, 07:13:44 PM »
I understand we should FreeEntity entity, but what about Pivots when done with them?

Jim

Offline angros47

  • Jr. Member
  • **
  • Posts: 43
Re: FreeEntity
« Reply #1 on: February 22, 2020, 11:00:32 PM »
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)

Offline JBR

  • Jr. Member
  • **
  • Posts: 91
Re: FreeEntity
« Reply #2 on: February 23, 2020, 01:05:59 AM »
Trying to remove the pivot stalls my pc. It works fine without removing the pivot. ???

Code: [Select]
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

Offline angros47

  • Jr. Member
  • **
  • Posts: 43
Re: FreeEntity
« Reply #3 on: February 23, 2020, 01:15:42 AM »
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

Offline JBR

  • Jr. Member
  • **
  • Posts: 91
Re: FreeEntity
« Reply #4 on: February 23, 2020, 01:42:56 AM »
Can't find a way to unparent the pivot.

jim

Offline Matty

  • Hero Member
  • *****
  • Posts: 1029
    • MattiesGames
Re: FreeEntity
« Reply #5 on: February 23, 2020, 03:11:58 AM »
Set the parent to 0 should unparent it from memory.

Offline angros47

  • Jr. Member
  • **
  • Posts: 43
Re: FreeEntity
« Reply #6 on: February 23, 2020, 09:21:27 AM »
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

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal