Camera Delete

Blitz3D Forums/Blitz3D Beginners Area/Camera Delete

NTense(Posted 2003) [#1]
OK, I thought I could get rid of a camera by using FreeEntity, but I get an 'Object Does not Exist' error. I don't see a delete camera specific command. Is there something I'm missing?


EOF(Posted 2003) [#2]
FreeEntity works fine with cameras.
Are you calling it from a function by chance?
I get no errors at all. Even if I try to free a non existing entity.

Which version of Blitz3D are you using?


NTense(Posted 2003) [#3]
I'm using the latest version(1.83). I have a custom type holding the camera handle. The weird part is that I can unparent it (as I would any entity). I have it parented to a player model in the game.. All of this is occuring as I'm deleting all of the game pieces and jumping back into the main menu.

Type T_Camera
	Field ObjectHandle
	Field minDist#
	Field maxDist#
	Field FogR
	Field FogG
	Field FogB
	Field FogMin#
	Field FogMax#
	Field CamPivot
	Field MaxRot#
	Field xRot#
	Field yRot#
	Field xRotVel#
	Field yRotVel#
	Field CamTarget
End Type

Function CleanUpGame()
	For Player.T_Player = Each T_Player
		FreeEntity Player\Rider\CurrentWeapon\ObjectHandle
		Delete Player\Rider\CurrentWeapon
		
		FreeEntity Player\Rider\ObjectHandle
		Delete Player\Rider
		
		For reticle.T_reticle = Each T_reticle
			FreeEntity reticle\ObjectHandle
			Delete reticle
		Next
	
		FreeEntity Listener
		Listener = 0
		
		;FreeEntity Camera\ObjectHandle
		EntityParent Camera\ObjectHandle, 0
			
		FreeEntity Player\Ostrich\ObjectHandle
		Delete Player\Ostrich
				
		Delete Player
	Next

	; Reset Flags
	MainMenuFlag = 1
	MenuLoadFlag = 0
	SinglePlayerFlag = 0
	InGameFlag = 0
	CleanUpGameFlag = 0
End Function



Binary_Moon(Posted 2003) [#4]
is camera a global variable?

Also why do you have this

   For reticle.T_reticle = Each T_reticle
      FreeEntity reticle\ObjectHandle
      Delete reticle
   next


in the player loop. There is no point doing this for every player since they will all be deleted the first player that gets deleted.

In fact I would guess that's the problem with the camera as well.

If you have two players then the camera will get deleted the first time and the second time there won't be a camera to delete so blitz will (should) give an error.

Basically you should only free stuff to do with the current type.

Remove the listener from the loop as well. Freeing that more than once could cause errors also.


for Player.T_Player = Each T_Player
   FreeEntity Player\Rider\CurrentWeapon\ObjectHandle
   delete Player\Rider\CurrentWeapon
		
   FreeEntity Player\Rider\ObjectHandle
   Delete Player\Rider
		
   FreeEntity Player\Ostrich\ObjectHandle
   Delete Player\Ostrich
			
   Delete Player
next

for reticle.T_reticle = Each T_reticle
   FreeEntity reticle\ObjectHandle
   Delete reticle
Next

for camera.t_camera = each t_camera		
   FreeEntity Camera\ObjectHandle
   EntityParent Camera\ObjectHandle, 0
   delete camera
next

FreeEntity Listener
Listener = 0