Bus error when using dynamic_cast

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Oguz286
Posts: 35
Joined: Tue Oct 30, 2007 4:56 am

Bus error when using dynamic_cast

Post by Oguz286 »

Hello everyone,

I have some dynamic casts in my code which works perfectly on my pc, but when I run the same app on the PSP, it gives me a bus error. I use the casts to cast a base class into an inhereted class which makes my life easier to handle objects, but it seems the PSP doesn't like it.

Code: Select all

Texture* tex = new StaticTexture();

StaticTexture* temp = dynamic_cast<StaticTexture*>&#40;tex&#41;;

if&#40;temp&#41; &#123;
    // do stuff
&#125;
Anyone got ideas?
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Use psplink or psp-addr2line or something to figure out where the bus error is. Possibly an alignment issue.
User avatar
Oguz286
Posts: 35
Joined: Tue Oct 30, 2007 4:56 am

Post by Oguz286 »

I'm using psplink so that's why I know there is a bus error, but I have no idea how to figure out where exactly it's happening, but I know it's happening on the dynamic_cast line in my first post. I looked at the psp-addr2line tool but I don't know what to input into the tool.

Code: Select all

Load/Start host0&#58;/engine.prx UID&#58; 0x045C577B Name&#58; "OguEngine"
host0&#58;/> Exception - Bus error &#40;data&#41;
Thread ID - 0x045B8407
Th Name   - user_main
Module ID - 0x045C577B
Mod Name  - "OguEngine"
EPC       - 0x08AA6A10
Cause     - 0x1000001C
BadVAddr  - 0x740410C5
Status    - 0x20088613
zr&#58;0x00000000 at&#58;0x2008FF00 v0&#58;0x00000010 v1&#58;0x08B5FA28
a0&#58;0x00000000 a1&#58;0x08AF7E60 a2&#58;0x08AF7E8C a3&#58;0x00000000
t0&#58;0x00000000 t1&#58;0x00000001 t2&#58;0x08B3C3F0 t3&#58;0x08B986A0
t4&#58;0x08B3C3E8 t5&#58;0x00001E04 t6&#58;0x08A35D70 t7&#58;0x20088600
s0&#58;0x08BF2440 s1&#58;0x09FBFD04 s2&#58;0x00000001 s3&#58;0x000000D8
s4&#58;0x08AF7E60 s5&#58;0x000000FF s6&#58;0x00000001 s7&#58;0x09FBFCE8
t8&#58;0x00000000 t9&#58;0x00000000 k0&#58;0x09FBFF00 k1&#58;0x00000000
gp&#58;0x08B44AB0 sp&#58;0x09FBFC28 fp&#58;0x09FBFEA0 ra&#58;0x089D04C0
0x08AA6A10&#58; 0x8C830000 '....' - lw         $v1, 0&#40;$a0&#41;
I can't tell if it's a memory alignment issue, because I have no code that aligns variables.

I started the debugger on psplink with debug ./engine.prx but that's as far as I get.
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Re: Bus error when using dynamic_cast

Post by hlide »

Oguz286 wrote:Hello everyone,

I have some dynamic casts in my code which works perfectly on my pc, but when I run the same app on the PSP, it gives me a bus error. I use the casts to cast a base class into an inhereted class which makes my life easier to handle objects, but it seems the PSP doesn't like it.

Code: Select all

Texture* tex = new StaticTexture&#40;&#41;;

StaticTexture* temp = dynamic_cast<StaticTexture*>&#40;tex&#41;;

if&#40;temp&#41; &#123;
    // do stuff
&#125;
Anyone got ideas?
yes i have a strong idea : the option -nortti gives you no dynamic_cast since this one relies on RTTI
User avatar
Oguz286
Posts: 35
Joined: Tue Oct 30, 2007 4:56 am

Re: Bus error when using dynamic_cast

Post by Oguz286 »

hlide wrote:
Oguz286 wrote:Hello everyone,

I have some dynamic casts in my code which works perfectly on my pc, but when I run the same app on the PSP, it gives me a bus error. I use the casts to cast a base class into an inhereted class which makes my life easier to handle objects, but it seems the PSP doesn't like it.

Code: Select all

Texture* tex = new StaticTexture&#40;&#41;;

StaticTexture* temp = dynamic_cast<StaticTexture*>&#40;tex&#41;;

if&#40;temp&#41; &#123;
    // do stuff
&#125;
Anyone got ideas?
yes i have a strong idea : the option -nortti gives you no dynamic_cast since this one relies on RTTI
Yes you are right, CpuWhiz just told me the same. It works now, thanks!
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

For furture reference you should be able to do in pspsh:
calc $epc-$mod
!psp-addr2line -e engine.elf $?
As long as you built with the -g switch and ensure you use the ELF not the PRX as that contains the debug info.
Post Reply