Help with exception...[SOLVED]

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
arpaagent
Posts: 10
Joined: Thu Sep 06, 2007 12:50 pm

Help with exception...[SOLVED]

Post by arpaagent »

Ok, running a program of mine using psplink sometimes it freezes up, and throws the following exception:

Code: Select all

ms0:/PSP/GAME150/0test/>  ./eboot.pbp
Load/Start ms0:/PSP/GAME150/0test/eboot.pbp UID: 0x05045F07 Name: 0test
ms0:/PSP/GAME150/0test/>  Exception - FPU Exception (IUV)
Thread ID - 0x05019A19
Th Name   - user_main
Module ID - 0x05045F07
Mod Name  - 0test
EPC       - 0x089065D0
Cause     - 0x1000003C
BadVAddr  - 0x00008000
Status    - 0x20008613
zr:0x00000000 at:0x08940000 v0:0x00000000 v1:0x08A10000
a0:0x089E9F48 a1:0x09EFFD44 a2:0x089E9F3C a3:0x09EFFD44
t0:0x00000003 t1:0x08A11BF0 t2:0x08A11C40 t3:0x1AD08A39
t4:0x00000006 t5:0x401AD08A t6:0x180174A0 t7:0x00000000
s0:0x08A153C4 s1:0x00000000 s2:0x089E9F3C s3:0x00000024
s4:0x089F0000 s5:0x09EFFD44 s6:0x00000000 s7:0x00000000
t8:0x11DF46AA t9:0x00000000 k0:0x09EFFF00 k1:0x00000000
gp:0x
Using psp-addr2line i found out where the exception is occurring. zvar is just a typedef of float, and v3z is a typedef of ScePspFVector3. The weird thing is that i check both pointer inputs for null, but then in the middle of the function it is getting a bad pointer of some sort. Is the stack getting overflowed or corrupt or something? At first i thought fabs( ) was messing with me (that's why you see it commented out) but after taking that out i still get an exception. Exception location is pointed out below.

Also interesting to note that this function works fine most of the time...it runs hundreds of times each game loop, and only throws an error occasionally.

Code: Select all

zvar quickDist2z( v3z * p1, v3z * p2 )
{
    if ( !p1 || !p2 )
    {
        null_ptr_count++;
        return 0;
    }
    zvar a = p2->x - p1->x;
    if &#40; a < 0 &#41; a = -a;
    zvar b = p2->y - p1->y;         //<------- exception here
    if &#40; b < 0 &#41; b = -b;
    return &#40;b+a&#41;/2.0f;
    //return &#40; fabs&#40; p2->x - p1->x &#41; + fabs&#40; p2->y - p1->y &#41; &#41;/2;
&#125;
Any thoughts or insights would be greatly welcome. I have tried running psp-gdb, but it doesn't seem to work. I am compiling with -g and i follow the instructions in the psplink manual but whenever i try to do psp-gdb ....etc target remote etc ... it times out.

Thanks!
Last edited by arpaagent on Sun Sep 23, 2007 4:07 pm, edited 1 time in total.
woo
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

IUV indicates numeric underflow which is causing the exception.
Disable the underflow FPU exception.
Same problem as here, I think.
http://forums.ps2dev.org/viewtopic.php?t=8688

Jim
arpaagent
Posts: 10
Joined: Thu Sep 06, 2007 12:50 pm

Post by arpaagent »

Thanks!

I disabled the FPU exceptions, and it no longer hangs, but now instead I get NaNs, and then my objects disappear. So I guess i'll have to track down the real source of the issue.
woo
arpaagent
Posts: 10
Joined: Thu Sep 06, 2007 12:50 pm

Post by arpaagent »

Ok I figured out what the root of the problem was.

Well, I was using the ScePspFVector3, and i'm doing a lot of 2d stuff, so i'm not really worrying about the z-component of the vector a lot of the time. Unfortunately, this lead to me no initializing the z component in some cases, leaving it to be whatever the current state of the memory was whenever I grabbed one. This was ok while just doing x and y component operations, but occasionally i did use the z-component, and i guess sometimes the unitialized value that ended up in the z-component happened to be something that the FPU did not like. So, after making sure to init the z-component to zero in some of my functions, it seems to solve the problem.

Thanks for your initial help with this!
woo
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Thanks for posting back!
Post Reply