Drawing sprites on PSP crashes the console

Hello community,
I have written a small SDL2 “hello world” application for the PSP which loads and draws a sprite on blue background (after pressing the x button). Here is the source of my project.
Everything works fine using the emulator “PPSSPP” but once I try the project on my PSP and PS Vita it always crashes the moment I press the x button which triggers the drawing of the texture. I’ve tried the SDL2 version that comes with the pspdev-toolchain and also compiled SDL2 for the PSP from source myself. I’ve tried png and bitmap as source format.
I’m putting the thread to sleep so you can see the message that the image was indeed successfully loaded on the screen. I’m also checking for null pointers and errors but once the code reaches SDL_RenderCopy(…); both console crash. I’m not able to check SDL_GetError() because the console becomes immediately unresponsive until the console shuts itself down.

I’ve exhausted my ideas for now and hope that someone here might have an idea :slight_smile:

Thanks to the helpful PSP homebrew community on Discord I found out how to debug and I found the place in the SDL2 source where it is supposedly crashing.

First of all that’s the PSP dump I got:

host0:/> ./Tutorial.prx
Load/Start host0:/Tutorial.prx UID: 0x00CD4935 Name: "Tutorial"
host0:/> Exception - Coprocessor unusable
Thread ID - 0x048CAD41
Th Name   - user_main
Module ID - 0x00CD4935
Mod Name  - "Tutorial"
EPC       - 0x088433C4
Cause     - 0x2000002C
BadVAddr  - 0x02038410
Status    - 0x20088613
Address   - 0x0003F3C4
zr:0x00000000 at:0x00000001 v0:0x42000000 v1:0x00000020
a0:0x08B14CE0 a1:0x08B15740 a2:0x00000000 a3:0x0BBBFD70
t0:0x0BBBFD60 t1:0x00000000 t2:0x00000000 t3:0x00000000
t4:0x00000000 t5:0x00000000 t6:0x00000000 t7:0x00000000
s0:0x08B14CE0 s1:0x08B151D0 s2:0x08B15740 s3:0x08843334
s4:0x00000013 s5:0xDEADBEEF s6:0xDEADBEEF s7:0xDEADBEEF
t8:0x00000000 t9:0xDEADBEEF k0:0x0BBBFF00 k1:0x00000000
gp:0x08A068A0 sp:0x0BBBFCC0 fp:0x0BBBFDB8 ra:0x0883E62C
0x088433C4: 0x48E20000 '...H' - mtv        $v0, S000

I could then turn the address into source code (since I’ve compiled both the homebrew and SDL as debug):

$ psp-addr2line -e Tutorial.elf 0x0003F3C4

This is the source on Github: https://github.com/libsdl-org/SDL/blob/SDL2/src/render/SDL_render.c#L611
I’ve compared it with the line of my local file because I was surprised that if (retval < 0) could be an issue.

I hope this can help us find the issue.

Good news a friendly person on Discord has given me the solution.
You have to add the following line to your main c/cpp file:

And to add all the information, the actual error seems to have been in SDL/src/render/psp/SDL_render_psp.c:136. After messing with the Makefile the debugger has given me this line which makes more sense.