SDL error when no SDL involved

Started by
6 comments, last by cignox1 19 years, 1 month ago
Hi, I have a strange problem that involves (so it seems) SDL, but the code where tha error occours does not use SDL Well, I have a simple geometric library I've written for some ray tracing tests. In the ray/triangle intersection routine there is the following line: real dist; . . . dist = -((r.GetOrigin() - v[0]) ^ normal) / (r.GetDir() ^ normal); where r is the ray, v[0] is a vertex of the current polygon and normal is the normal of the polygon. I use SDL to output the rendering results. Right at that line the program crashes and the following line is written on the console: Fatal signal:Segmentation Fault <SDL Parachute Deployed> I use winXP and Mingw, latest versions of MingW and SDL. The previous code worked well some ago. Then I did many changes to the application testing it only with spheres. Then I tried the polygons and that happens. Sorry for the lack of informations, if you have an idea (or want to have more code) then just say it. Thank you! EDIT: I forget to say that if I comment out this line, the error does not occour!
Advertisement
i dont know either what that has to do with SDL, but i cant blame your compiler for failing to figure out that line. what does it do? the ^operator evidently returns a vector, otherwise you couldnt substract the result from origin, a vector also i assume.

but then you proceed to divide two vectors by eachother? storing the result in a real... that has me confused, maybe your compiler aswell?
Quote:Original post by Eelco
i dont know either what that has to do with SDL, but i cant blame your compiler for failing to figure out that line. what does it do? the ^operator evidently returns a vector, otherwise you couldnt substract the result from origin, a vector also i assume.

but then you proceed to divide two vectors by eachother? storing the result in a real... that has me confused, maybe your compiler aswell?


Agreed. The ^ operator is a bitwise XOR. If you are wanting to do powers, you must do something this:
dist = - pow(r.GetOrigin() - v[0],normal) / pow(r.GetDir(),normal);


That's assuming r.GetOrigin() returns some simple data type as well as r.GetDir(). If you are returning vectors, you might need to do some operator overloading (of which you cannot overload ^) and handle it like that. You are getting a SDL error with non-sdl code because you are generating an illegal instruction in a SDL program, so SDL must quit as well as all of its subsystems.

[edit] So you can overload the ^ operator [lol]. Silly me.

[Edited by - Drew_Benton on March 8, 2005 1:30:05 PM]
SDL catches fatal exceptions like this one (which is an access violation). Your code is throwing it, but SDL's error routines are catching it.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Yeah, sorry, I had to be more clear: the ^ operator is the dot product on vectors, so the line

dist = -((r.GetOrigin() - v[0]) ^ normal) / (r.GetDir() ^ normal);

has the form real = real / real;

(I overloaded the operator ^ as the dot product on vectors).

I've found that the error is elsewhere. Tomorrow I will do some tests and eventually I will post some more informations. Thank you aniway!
my guess is that '(r.GetDir() ^ normal)' is be returning 0, and causing a divide-by-zero error.
use SDL_Init( .... SDL_INIT_NOPARACHUTE ) to get rid of this message, the app then may just crash :)
Quote:
my guess is that '(r.GetDir() ^ normal)' is be returning 0, and causing a divide-by-zero error.


Yes, I thought that too, but then I checked it and it is never 0. I've solved the problem, it was just a null pointer not handled in the proper way in another function. This stupid error has wasted my time, but yours also, so sorry. Thank you anyway!

This topic is closed to new replies.

Advertisement