Error Type Objetc Help.

Blitz3D Forums/Blitz3D Programming/Error Type Objetc Help.

Yue(Posted 2015) [#1]

; Objeto Bone.
; ==============
Function Init_ObjBone.CBone( entidad%, nombreBone$, nombre$="")
	
	
	Local obj.CBone = New CBone
	
	obj.CBone\mesh% = entidad% ; <<<<<<<<<< 
	obj.CBone\bone% = RecuperarBone%( obj\mesh%, nombreBone$ ) 
	
	If nombre$ = "" Then 
		
		idBone% = idBone%  + 1
		obj.CBone\nombre$  = "Bone Ragdoll " + idBone% 
		
	Else 
		
		obj.CBone\nombre$   = nombre$
	End If 
	
	
	If obj.CBone <> Null And obj.CBone\bone%> 0 Then 
		
		
		InfoDepurador(obj.CBone\nombre$)
	Else 
		InfoDepurador(obj.CBone\nombre$,"Fail")
		
		
	End If 
	
	
	
	Return obj.CBone
	
	
End Function 

Function DeleteObjBone%()
	
	Local obj.CBone = New CBone
	
	If obj.CBone <> Null Then 
		
		For obj.CBone = Each CBone	
			
			obj.CBone\nombre$ = ""
			
			
			If   obj.CBone\bone% > 0 Then 
				
				FreeEntity obj.CBone\bone%
				obj.CBone\bone% = 0
				
			End If 
			If obj.CBone\mesh% > 0   Then 
				
				;RuntimeError EntityClass(obj\mesh% ) ; <<<<Return Mesh.
				
				FreeEntity obj.CBone\mesh% ; Error.
				obj.CBone\mesh% = 0
			
				
				
			End If
			
			
		Next
		
		Delete obj.CBone
		
	End If 
	
	
End Function 



Help please.


_PJ_(Posted 2015) [#2]
I think the problem is because here:
Local obj.CBone = New CBone
You are creating a NEW object instance

So it will defintitely NOT be Null here:

If obj.CBone <> Null Then

But then you have

For obj.CBone = Each CBone

So you are using the same "pointer" of obj.CBone that was for the NEW instance, and now using it to iterate through FOR/EACH instances of every CBone object.

I hope that makes sense.

I see you are wanting to iterate thoro0ugh your object instances to ensure all the entitys are freed before destroying them, there's no need to declarte a new instance at all, you simply just need the iteration (Null objects wont even be included) so the following should work:

Also, IF the CBone\Bone are child entities of CBone\Mesh, they will automatically be freed recursively with the Mesh entity.


Function DeleteObjBone%()
	Local obj.CBone
	For obj = Each CBone	
	If obj <> Null
		obj\nombre$ = ""
		If (obj\Mesh)								FreeEntity obj\mesh
		obj\Mesh% = 0
		End If 
                Delete obj
	End If
End Function



Yue(Posted 2015) [#3]
;)

Function DeleteObjBone%()
	
	Local obj.CBone ; Thanks You :) 
	
	If obj.CBone <> Null Then 
		
		For obj.CBone = Each CBone	
			
			obj.CBone\nombre$ = ""
			
			
			If   obj.CBone\bone% > 0 Then 
				
				FreeEntity obj.CBone\bone%
				obj.CBone\bone% = 0
				
			End If 
			If obj.CBone\mesh% > 0   Then 
				
				FreeEntity obj.CBone\mesh% ; >> NO Problem.
				obj.CBone\mesh% = 0
				
			End If
			
			
		Next
		
		Delete obj.CBone
		
	End If 
	
	
End Function