Author Topic: X_COLLISIONRAY crash  (Read 4146 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
X_COLLISIONRAY crash
« on: 2012-May-27 »
My program will crash when it hits the X_COLLISIONRAY line in the following section of code - but only when debug is disabled

Code: (glbasic) [Select]

LOCAL x,y,z, x2,y2,z2
X_SCREEN2WORLD MouseX, MouseY,  0, x, y, z
X_SCREEN2WORLD MouseX, MouseY, -1, x2,y2,z2
// DEBUG M_Hill+","+x+","+y+","+z+","+x2+","+y2+","+z2
// END
IF X_COLLISIONRAY(M_Hill, 0, x, y, z, x2-x, y2-y, z2-z)<>0
MouseCollisionFace=X_GETCOLLISIONFACE() // div by 3 for x_getcollisionface bug, then divide by 2 to get the right triangle
X_GETFACE M_Hill, 0, MouseCollisionFace, Face[]
DEBUG "Collision = "+MouseCollisionFace+",X="+Face[0][0]+",Y="+Face[0][1]+",Z="+Face[0][2]+",nx="+Face[0][6]+",ny="+Face[0][7]+",nz="+Face[0][8]+"\n"
ELSE
MouseCollisionFace=-1
ENDIF

If I turn debug on, there's no crash. By uncommenting the two commented lines I can see I have valid variables to pass to the command :
Code: (glbasic) [Select]
Injection started

7,-6.900289536,1.999999642,3.900290012,-6.900289536,1.999999642,3.900290012
By putting "END" commands straight after the "IF" and "ELSE" lines, I can prove it's the X_COLLISIONRAY on the first execution of the code that crashes the program.

My setup is Windows XP, GLBasic 10.283

MrTAToad

  • Guest
Re: X_COLLISIONRAY crash
« Reply #1 on: 2012-May-27 »
Is it crashing inside the IF/ELSE block or the actual command ?

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #2 on: 2012-May-27 »
No, the command crashes.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #3 on: 2012-May-28 »
HI a few days I used this command and don´t crash, perhaps it´s Xgetface, I´m not used, in the code containing X_raycollision..

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #4 on: 2012-May-28 »
It is definitely the line containing X_COLLISIONRAY that crashes the program as I ran the following test and the program still crashes when not in debug mode.

Code: (glbasic) [Select]
IF X_COLLISIONRAY(M_Hill, 0, x, y, z, x2-x, y2-y, z2-z)<>0
                END
ELSE
                END
ENDIF
« Last Edit: 2012-May-28 by FutureCow »

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1621
  • Particle Hawk
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #5 on: 2012-Jun-14 »

hmm interesting codesnip...is this a "test" to see who can see what you see? lol

if then end, else end...

its ending the program not crashing.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #6 on: 2012-Jun-14 »
As noted on the initial post
Quote
By putting "END" commands straight after the "IF" and "ELSE" lines, I can prove it's the X_COLLISIONRAY on the first execution of the code that crashes the program.
I posted the actual code described by that code in response to metalthinks questioning whether it was one of the commands in the IF statement.

The result was definitely a crash with a "do you want to report the problem to Microsoft" query.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1621
  • Particle Hawk
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #7 on: 2012-Jun-14 »
Does the sample in the help file crash too?

More dumb questions(my forte):
Is your collisionray before or after all the x_make3d?
Have you already created/loaded the object before testing the command?
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #8 on: 2012-Jun-14 »
Hi Future, I do this code... it´s based in your code.

The Code it´s attached, don´t care too much to read in these Lines.
Code: (glbasic) [Select]
// --------------------------------- //
// Project: xcollision
// Start: Thursday, June 14, 2012
// IDE Version: 10.283


// SETCURRENTDIR("Media") // go to media files

GLOBAL M_Hill = 100
GLOBAL Face[]
//X_LOADOBJ "Media/objX_ship_Interior_01.ddd", M_Hill

X_LOADOBJ "Media/Box001.ddd", M_Hill

GLOBAL MouseX,MouseY
GLOBAL b1,b2
WHILE TRUE
MOUSESTATE MouseX,MouseY,b1,b2

render()
//STATIC x,y,z, x2,y2,z2
LOCAL x,y,z, x2,y2,z2

X_SCREEN2WORLD MouseX, MouseY,  0, x, y, z
X_SCREEN2WORLD MouseX, MouseY, -1, x2,y2,z2
// DEBUG M_Hill+","+x+","+y+","+z+","+x2+","+y2+","+z2
// END

STATIC MouseCollisionFace
IF X_COLLISIONRAY(M_Hill, 0, x, y, z, x2-x, y2-y, z2-z)<>0
LOCAL color = RGB(255,0,0)
X_LINE x, y, z, x2-x, y2-y, z2-z, 2,color
MouseCollisionFace=X_GETCOLLISIONFACE() // div by 3 for x_getcollisionface bug, then divide by 2 to get the right triangle
X_GETFACE M_Hill, 0, MouseCollisionFace, Face[]
DEBUG "Collision = "+MouseCollisionFace+",X="+Face[0][0]+",Y="+Face[0][1]+",Z="+Face[0][2]+",nx="+Face[0][6]+",ny="+Face[0][7]+",nz="+Face[0][8]+"\n"

message_Screen()
ELSE
MouseCollisionFace=-1
ENDIF


SHOWSCREEN
WEND

FUNCTION render:

STATIC phi
X_MAKE3D 1,1000,45
X_CAMERA 0,0,40 , _
0,0, 0


IF phi<360
INC phi
ELSE
  phi=0
ENDIF

X_MOVEMENT 0+(COS(phi)*100),0,-300
X_ROTATION phi,1,1,1
X_DRAWOBJ M_Hill,0
ENDFUNCTION

FUNCTION message_Screen:
X_MAKE2D
PRINT "Now Have collision" , 0 , 0
ENDFUNCTION

Have a little "more complex" collision becuase the object it´s moving... for me your code works fine, in Debug mode too, I only think in the local variables, I put in static , but I turn again to put in Local and works equal...

I think, but this it´s only a speculaton, perhaps the problem it´s the model, I don´t know if it´s a model from a 3D suite or it´s a runtime model... perhaps can be too the extension... I always use .ddd, and never have troubles...

You have attached the complete Code:

PS: Future only a think try to put in your code, when decalare the array for get the faces, try to put global and not in Local... and we see what´s happend


[attachment deleted by admin]

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10815
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: X_COLLISIONRAY crash
« Reply #9 on: 2012-Jun-14 »
or send in the working example that crashes.

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
Re: X_COLLISIONRAY crash
« Reply #10 on: 2012-Jun-15 »
Damn! I can't get it to crash now I've added a bit to my program! I'll keep trying and if I can reproduce it I'll upload the example code.
Sorry, I should've thought to do that when I posted the bug report.