FreeEntity no delete.
Blitz3D Forums/Blitz3D Programming/FreeEntity no delete.
| ||
Graphics3D 800, 600, 32 SetBuffer BackBuffer() cubo% = CreateCube() FreeEntity cubo% RuntimeError cubo% ; Return 12556698 While Not KeyHit(1) Wend What is this about? |
| ||
Graphics3D 800, 600, 32, 2 cubeR% = CreateCube() DebugLog(cubeR) FreeEntity(cubeR) DebugLog(cubeR) cubeR = 0 DebugLog(cubeR) WaitKey() End() As i understand it : cubeR represents an integer variable. This integer variable is used to store the reference/pointer of a mesh (a cube) When you use freeentity(), this deletes/frees the mesh, not the reference/pointer Hence the necessity to reset the integer variable after the associated pivot, mesh, surface, texture, animation, image, font, sound, has been deleted/freed. (If you want the variable to be equal to 0, this is not really necessary if your code does not reuse this variable to access a thing after has been deleted/freed...) |
| ||
its about reading the manual FreeEntity |
| ||
Also... :) |
| ||
What happens is that I have a Brush, during the creation of SkyBox removes the brush , but then in order to create the reference to the brush at the end of the program does the following for obj.CBrush = Each TBrush if obj\brush% then FreeBrush(obj\brush%) end if delete obj.Cbrush next I remember in a previous program to create heaven brush part was already eliminated . Then when exiting the program it tells me that the brush does not exist and does not remove pued . |
| ||
The reason is that all Blitz3D functions are "call by value". That means that if you do this: angle = 10 Print Sin( angle ) The Sin function does not get access to the angle variable. Only the value, 10, is passed to the function. It is exactly the same as if you had done this angle = 10 Print Sin( 10 ) In your cube example FreeEntity knows only the value of the variable, in effect doing cubo% = CreateCube() FreeEntity 12556698 RuntimeError cubo% ; Return 12556698 So FreeEntity can't set the variable to zero as you would want it to do. You have to do it yourself. For the brush code you need if obj\brush% then FreeBrush(obj\brush%) obj\brush = 0 end if This works for inside Types, such as obj\brush. But it would fail if you wrote a function for simple variables: Function MyFreeEntity( ent ) FreeEntity ent ent = 0 End Function c = CreateCube() MyFreeEntity( c ) ; will free the cube c, but will not set c = 0. This is because MyFreeEntity( c ) gets only the value of c. It then creates a local variable named ent and assigns it a value with ent = c. Then FreeEntity ent will free the cube c, but setting ent = 0 does not set c = 0. |
| ||
Ok, Thanks You. :) |