Weird crash

Blitz3D Forums/Blitz3D Programming/Weird crash

Shambler(Posted 2005) [#1]
I have been trying to track down a bug in my code but so far have drawn a blank.

The following code will crash back to the IDE with no error and debug on.
If LinePick(EntityX(o\colmesh%,True),EntityY(o\colmesh%,True),EntityZ(o\colmesh%,True),0,o\height#,0,1)>0
EntityParent o\colmesh%,PickedEntity()
Else
MoveEntity o\colmesh%,0,-0.5,0
EndIf

If I create an .exe it will crash with the error 'Stack OverFlow!'

Changing to line pick to this removes the problem.
If LinePick(EntityX(o\colmesh%,True),EntityY(o\colmesh%,True)+1,EntityZ(o\colmesh%,True),0,o\height#,0,1)>0
EntityParent o\colmesh%,PickedEntity()
Else
MoveEntity o\colmesh%,0,-0.5,0
EndIf

I assumed I was either making one of the following errors,
1) parenting the entity to itself
2) parenting the entity to one of its children

I checked for both but this was not the case, although the problem has gone away by adding 1 to the LinePick Y coord I really would like to know what was causing it =/


DJWoodgate(Posted 2005) [#2]
I would have thought it was a parenting error as well. See if you can simplify the issue to some example code.


jfk EO-11110(Posted 2005) [#3]
Stack overflow clearly suggests that you self-parented an entity (directly or indirectly), that is strictly forbidden in 3D Hierarchies since it messes up any computer.

It's very simple, an entity may never be child of itself, no matter how many generations far away.

If you try:

d1=createcube()
d2=createcube()
entityparent d1,d2
entityparent d2,d1

and run it, you'll get a stack overflow.

If you do such a thing in a modeller, it usually refuses to do so, saying looped parent relations not allowed.

EDIT - uh, sorry shambler if I sounded like I was talking to a kindergarden kid. I just used to read your whole post.

Additionally I have to say when you force such a self-parenting error, the Debugger says "Entity cannot be parented to itself!". So your problem may be something diffrent.

EDIT2 - if you parent 10 thousand cubes to one another and then in the end parent cube 0 to cube 10000 (a loop over 10000 entities), the debugger doesn't only say the mentioned error message, but also creates a stac overflow and two BlitzCC Crash Win-Api Messages. So parent errors may react individually.


Shambler(Posted 2005) [#4]
This one is still being a pain lol, even this crashes.

Unparent the entity o\colmesh%
Unparent the entity I want to parent it to 'PickedEntity()'
Try to parent o\colmesh% to PickedEntity()=crash
If LinePick(EntityX(o\colmesh%,True),EntityY(o\colmesh%,True),EntityZ(o\colmesh%,True),0,o\height#,0,1)>0
EntityParent o\colmesh%,0
EntityParent PickedEntity(),0
EntityParent o\colmesh%,PickedEntity() ;boom!
EndIf


This is going to take some tracking down O.o

[EDIT]

If I
EntityColor PickedEntity(),255,0,0

then the room that the object is in turns red which I would expect, so the PickedEntity() is a valid mesh.


Shambler(Posted 2005) [#5]
Found it!!!

A bug in the following function

Function Recursive_Alpha(mesh%,alpha#)

Local c%
Local count%=CountChildren (mesh%)

EntityAlpha mesh%,alpha#

If count%>0
For c%=1 To count%
Recursive_Alpha(mesh%,alpha#)
Next 
EndIf

End Function 


which should have been

Function Recursive_Alpha(mesh%,alpha#)
Local c%
Local count%=CountChildren (mesh%)

EntityAlpha mesh%,alpha#

If count%>0
For c%=1 To count%
Recursive_Alpha(GetChild(mesh%,c%),alpha#)
Next 
EndIf
End Function 


The room meshes 'mesh%' don't actually have children any more, if they did have then the program should have gone into an endless loop.

This doesn't explain to me though why it broke the parenting of another mesh to one of these room meshes.


jfk EO-11110(Posted 2005) [#6]
nice to see it was a simple typo thing.

BTW:
Maybe you should use
If EntityClass$(mesh%)="Mesh" then EntityAlpha mesh%,alpha#

to prevent MAVs with Meshes that are containing Bones or plain Pivots as children.