Problem returning model pointer

Blitz3D Forums/Blitz3D Programming/Problem returning model pointer

Shifty Geezer(Posted 2004) [#1]
In a function I return a created model using CopyMesh(). Up to now I have had one array for these models, and a separate array for Tokamak geometries. I've redesigned this to incorporate both geometry and Tokamak object pointer into a custom type including other properties like this.

Type TOK_actor
	; TOK_actors are rigid bodies (rb_TOK...) that interact in motion within the TOK simulation
	; They have geometry type, size, position, rotation, and velocity giving motion, ang and lin dampening
	Field geom% ; Geometry type, CUBE, SPHERE, PILL
	Field model% ; Pointer to geometry
	Field TOK_obj% ; Pointer to Tokamak reference
	
	Field siz_x#
	Field siz_y#
	Field siz_z#
	
	Field pos_x#
	Field pos_y#
	Field pos_z#
	
	Field rot_x#
	Field rot_y#
	Field rot_z#
	
	Field vel_x#
	Field vel_y#
	Field vel_z#
	
	Field linear_damp#  
	Field angular_damp# 
	Field material%  
	Field mass#	
	
End Type

I have a function that returns a copy of a mesh depending on parameters with a call such as...
actors(n)=create_geometry_actor(actor.TOK_actor)

Function create_geometry_actor(src.TOK_actor)
	entity=copy_mesh(blah blah)
	Return entity
End function

This worked fine, but now I have moved the array storing model data into an array of type and reference it thus
actors(n)\model=create_geometry_actor(actor.TOK_actor)

I get an "Object does not Exist" error, even though during Debug entity has a value copied from the mesh.

Any clues?


semar(Posted 2004) [#2]
I would try:
actors(n)\model=create_geometry_actor(actor)

or also
entity = create_geometry_actor(actor)
actors(n)\model = entity


Shifty Geezer(Posted 2004) [#3]
Yeah, I had that for my actors() array, but not my props() array which is where it was keeling over. The object not existing was for the return and not the object being passed.


PowerPC603(Posted 2004) [#4]
Have you created the type instance yet, before calling the function, which returns the model's handle?

dim actors.TOK_actor(NumberOfActors)

; Create as many type-instances as there are indexes in the array and store the pointer to each instance in the array
for i = 0 to NumberOfActors
actors(i) = new TOK_actor
next

actors(n) = create_geometry_actor(actor.TOK_actor)


The problem can be that the function DOES return the correct handle for your new mesh, but cannot store it into the array, because the type-instance doesn't exist yet for that specific array-index (= n).


Shifty Geezer(Posted 2004) [#5]
Yes, That was the problem and it's all fixed now. Only, now there's other problems with my code :(