Scalemesh memory access violation

Blitz3D Forums/Blitz3D Programming/Scalemesh memory access violation

Craig H. Nisbet(Posted 2004) [#1]
Hey guys,

Ran into a weird problem, I have a program that I previously use the scaleentity command, but now I want to replace it with the scalemesh command. It's only called once per entity. Anyway, when I swapped the code from scaleentity to scalemesh, I get a memory access violation. This doesn't make much sence to me because the other function worked fine. Any ideas?


Stevie G(Posted 2004) [#2]
Have you turned debug on to give you a better idea of what the error is?

It's possible I'm barking up the wrong tree here but ..

Have you got an original mesh which you take copies of and then apply scaleentity to? If you've done this and then freed the original the scalemesh command will still be trying to access the orignal entity. Maybe try using copymesh.


Ross C(Posted 2004) [#3]
Maybe it's something to do with you using copyentity then scalemesh?


Shambler(Posted 2004) [#4]
Graphics3D 800,600

camera=CreateCamera()


cube#=CreateCube()

ScaleEntity cube,1,1,1

;ScaleMesh cube,1,1,1 ;run this line to get a MAV =)

While Not KeyHit(1)
RenderWorld()

Text 0,0,"program running"
Flip
Wend



Difference(Posted 2004) [#5]
cube#=CreateCube() !!

tsk, tsk, cube%=CreateCube()


(tu) sinu(Posted 2004) [#6]
make sure you assign stuff like meshes as integers, they aren't floats.


Craig H. Nisbet(Posted 2004) [#7]
Actually the model is a b3d file, but I'm sure that doesn't make any difference. I tried it in debug mode but I get the same error. My program is rather large now. It could be something from somewhere else.


sswift(Posted 2004) [#8]
Craig:
As peter said, NEVER EVER assign a handle to a floating point variable. Remove the # at the end of the variable name when you create the cube.

Additionally, if you still have the problem loading the B3D file, perhaps it's possible the file contains pivots or lights? I haven't actually used the B3D format much myself so I don't know if it can have NON-mesh entities contained in it.

It might be that a B3D mesh which has children and such has a pivot as the root entity... the parent entity, and that would be the one you're accessing when you use the handle.

Use countchildren on the entity after you load it, and see if that returns a number greater than 0. If so then the problem may well be that the root mesh is a pivot.

That is, asusming that the problem isn't just that you used a floating point variable to store the handle.


Shambler(Posted 2004) [#9]

cube#=CreateCube() !!

tsk, tsk, cube%=CreateCube()



That was the point of my post lol, I was trying to be subtle ^^


Craig H. Nisbet(Posted 2004) [#10]
I found my bug, it was in a different part of my code. It was trying to pass a camera entity in there. Like I said, the code was getting pretty big. Easy solution though.


Craig H. Nisbet(Posted 2004) [#11]
Wow, I have quite a challenge ahead of me. My code has many entities parented to each other. The shadow lib only casts on rotatemesh and scalemeshed entities. I'm assuming rotatemesh and scalemesh will not effect the children of that entity in the same manner as scaleentity and rotateentity. Unless I'm misstaken.


sswift(Posted 2004) [#12]
One entity parented to another is fine. YOu just have to pass the right pointer to the shadow system. You passed the pointer to a parent which was a camera apparently.

The system does not automatically shadow children of the entity you pass it for this very reason. So if you pass an entity that has a camera as a child it should work fine.

But I won't make any guarantees. :-)


"I'm assuming rotatemesh and scalemesh will not effect the children of that entity in the same manner as scaleentity and rotateentity."

They will not. But you could scale the children individually.

Why do you have children of an entity receivign a shadow? Does your level have children for doors and chairs and things?


sswift(Posted 2004) [#13]
Function Recursive_Shadow_Entity_And_Children(Entity)

	Cast_Shadow(Entity, 128)

	For Loop = 1 To CountChildren(Entity)
		
		ThisChild = GetChild(Entity, Loop)
		Recursive_Shadow_Entity_And_Children(ThisChild)
		
	Next

End Function



That function recursively applies a shadow to a mesh and all its children. You can easily modify it to instead apply a scalemesh to a mesh and all its children. All you need do is give the function three additional paramaeters for x y and Z scale and pass them on to the function again inside the loop so subsequent calls get the scale too.

One more thing... If you look in the versions.txt for Blitz3D, you will see information on a new command which was added a few versions back that tells you what kind of entity a particular entity is. You can use this information to make the function not apply a scalemesh to a non mesh entity. You could also modify the function above to not apply a shadow to a child entity as well.

I highly reccomend though that you not set every object in your level to receive shadows. The system is probably not capable of handling that, though I suppose if you set up your lights very carefully you _might_ get away with it.


Craig H. Nisbet(Posted 2004) [#14]
I've got the shadow system receiving great on entities that are completely static with no children. What I've been writing is a LW scene to Blitz Entity placement and system. I intend to use this to construct my levels for my game projects. As it stands, it imports position, rotation, scale, and animation on all the above for all the items in the Lightwave scene. This include the entity hierachy structure. This is mostly done and it works! As it stands, it is possible to have static mesh geometry that is in a heirachy of entities, and since it's an editor system, I don't want to put too many limitation on the form in which the level has to be constucted. I am considering unparenting the entities in world space and doing the meshrotate and meshscale from that point. I would prefer to retain the original hierarchy, but if it causes too much trouble, I guess I'll have to work around it. Either way, I'm pretty happy with the results as it stands right now.