Arbitrary code crashing PSP

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

Moderators: cheriff, TyRaNiD

Post Reply
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Arbitrary code crashing PSP

Post by AnonymousTipster »

In my latest project, I've been coming across some very wierd crashes. The crashes appear to be caused by completely unused sections of code. For example, I add in a function declaration:

Code: Select all

void DrawScreenQuad(struct Vertex Vert[2],unsigned char texture, int xpos, int ypos, int width, int height, int texWid, int texHei, int texBufWid);
void DrawScreenQuad(struct Vertex Vert[2],unsigned char texture, int xpos, int ypos, int width, int height, int texWid, int texHei, int texBufWid){
	if(texture){
Vert[0].x = xpos;
Vert[0].y = ypos;
Vert[0].z = 0;
Vert[0].u = 0;
Vert[0].v = 0;
Vert[1].x = xpos+width;
Vert[1].y = ypos+height;
Vert[1].z = 0;
Vert[1].u = texWid;
Vert[1].v = texHei;

sceGuTexMode(GU_PSM_8888,0,0,0);
sceGuTexImage(0,texWid,texHei,texBufWid,texture);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGBA);
sceGuTexFilter(GU_LINEAR_MIPMAP_LINEAR,GU_LINEAR_MIPMAP_LINEAR);
 
sceGumDrawArray(GU_SPRITES,GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_2D,2,0,Vert);
	}

}
In one of my header files, and the PSP crashes after everything is loaded. Commenting out the function makes the application work properly again.
This function is never referenced, it is completely arbitrary, yet causes a crash.
The PSP loads all the data, but crashes during the first loop, similar to an out-of-bounds array, but I can't work out why this arbitrary code could cause it.

This function isn't the only perpetraitor, another example is:
Working code:

Code: Select all

char* filePath;
build_path(filePath,skinDirectory,"MenuBar.png",0);
loadPNGvramfromfileoverwrite(filePath,512,64,(int)testMenuBar_temp);
Code that crashes:

Code: Select all

char* filePath;
filePath = NULL;
build_path(filePath,skinDirectory,"MenuBar.png",0);
loadPNGvramfromfileoverwrite(filePath,512,64,(int)testMenuBar_temp);
Again, a completely arbitrary change which causes a crash.

I'm not sure where to look for the problem, because there doesn't seem to be a problem. I'll include my makefile at the end of the post if that helps.
This problem is similar in nature to another one that I worked around on several projects using the GU - where the screen data is split in two, one shaded green and the other purple. To fix it, I would add an arbitrary bit of code. If anyone has come across this problem, it may help in solving my current situation.

I'm really hoping that someone knows why my code is crashing, because i'm finding it very hard to debug.
Thanks.

My Makefile:

Code: Select all

TARGET = browser
OBJS = main.o

INCDIR = "/home/Paul/pspgames/libungif/lib" "/home/Paul/pspgames/freetype/include"
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LDFLAGS =
LIBS= -lstdc++ -lpspgum -lpspgu -lpng -ljpeg -lungif -lz -lm -lfreetype -lpsppower -lpspsdk


EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = WebBrowserTest

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Other notes:
Code based on cube.c sample
Uses main .cpp file with several large .h files
C++ code
Uses GU code
Runs in user mode
Garak
Posts: 46
Joined: Wed Jul 27, 2005 1:59 am

Post by Garak »

Hello,

In C, when you rem out sections of code, the compiler will often organize variables in memory a little differently. Most likely, your bug is somehwre else in your code. As you sated, a pointer is probably pointing to something it ought not be, or maybe a thread you have created has overrun its stack.

When you rem out seemingly unrelated sections of code, the compiler re-compiles your stuff, and may place variables in memory a little differently. Thus, before your roughe pointer overwrote some data that did not cause the PSP to crash. When you re-compile remming out code, or even adding new code, the roughe pointer may end up writing to some area of memory that results in a crash.

I have seen this happen a lot. Good luck tracking it down...

Garak
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

Ah. Well, at least I have an answer. Looks like i'll be in for a few long nights.
Thanks, Garak.

I don't suppose there's any ways to run diagnostics on an EBOOT? To see which variables are overrunning?
urchin
Posts: 121
Joined: Thu Jun 02, 2005 5:41 pm

Post by urchin »

Another thing I've found help is to delete all .o files and rebuild all libraries that you are linking against, just in case something has got out of kilter.
rinco
Posts: 255
Joined: Fri Jan 21, 2005 2:12 pm
Location: Canberra, Australia

Post by rinco »

I bet you need to align a parameter or two. The documentation (ie: comments in pspgu.h) describes which parameters need to be aligned.
Post Reply