Sign in to follow this  

SDL error when no SDL involved

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this