| View previous topic :: View next topic |
| Author |
Message |
nataku92
Joined: 27 Dec 2005 Posts: 5
|
Posted: Mon Jul 24, 2006 8:34 am Post subject: fpu exception? |
|
|
I keep on getting an exception as shown by this image:
I've narrowed it down to a for loop in my update function that checks a whether a line segment(a bullet's previous position to its current position) intersects a circle(a person). Both the bullets and people are stored in a vector. The code is as follows:
| Code: |
for(unsigned int k=0; k<mBullets.size(); k++) {
Vector2D p1(mBullets[k]->pX,mBullets[k]->pY);
Vector2D p2(mBullets[k]->mX,mBullets[k]->mY);
Vector2D O = p1;
Vector2D D = p2-p1;
for(unsigned int j=0; j<mPeople.size(); j++) {
Vector2D C(mPeople[j]->GetX(),mPeople[j]->GetY());
float t = D.Dot(C-O)/D.Dot(D);
if (t < 0) {
t = 0;
}
else if (t > 1) {
t = 1;
}
Vector2D closest = O+t*D;
Vector2D d = C - closest;
float ll = d.Dot(d);
int r = 16;
if (ll < r * r) {
mPeople[j]->mHealth -= 20;
mPeople[j]->SetSpeed(mPeople[j]->GetSpeed()*0.5f);
mBullets.erase(mBullets.begin()+k);
k--; //makes up for the erase to prevent skipping bullets
}
}
}
|
It seems that the if (ll < r * r) { block at the end is causing the probem, since no exception happens if I comment out all the lines in the block. However, if I put any statement, even a simple one declaring an arbitrary int or something (like int random = 0;), it gives me the exception again. Any help or suggestions?
Thanks
btw, I'm using dr_watson's JGE++ Engine |
|
| Back to top |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Mon Jul 24, 2006 2:56 pm Post subject: |
|
|
remember precedence
this
if (ll < r * r) {
might be this
if ((ll < r) * r) {
or this
if (ll < (r * r)) { _________________ 10011011 00101010 11010111 10001001 10111010 |
|
| Back to top |
|
 |
nataku92
Joined: 27 Dec 2005 Posts: 5
|
Posted: Mon Jul 24, 2006 3:57 pm Post subject: |
|
|
still the same error T_T
its even weirder since I use almost the same exact code in a preceding for block to check the mPeople vector against line segments (walls) and that works fine. The only notable differences are that I use an array to hold the walls, while I use a vector for the bullets. Not really sure if that means anything though.. |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Mon Jul 24, 2006 4:46 pm Post subject: |
|
|
Could this line:
float t = D.Dot(C-O)/D.Dot(D);
Ever be divide by 0? If so, that might be the problem.
Else, type in psp-addr2line myapp.elf 0x089014CC which should give you the line of the problem. |
|
| Back to top |
|
 |
nataku92
Joined: 27 Dec 2005 Posts: 5
|
Posted: Mon Jul 24, 2006 4:55 pm Post subject: |
|
|
Ahhh thanks so much!! I forgot that the first time a bullet is initialized, its current and previous positions are the same. -.-'
Thanks!!
hm now to find out if that DEADBEEF thing is just some giant coincidence >_> |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
|
| Back to top |
|
 |
Oobles Site Admin
Joined: 17 Jan 2004 Posts: 362 Location: Melbourne, Australia
|
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Mon Jul 24, 2006 7:49 pm Post subject: |
|
|
| I call snap :) |
|
| Back to top |
|
 |
|