 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Sun Jan 01, 2006 2:51 am Post subject: Arbitrary code crashing PSP |
|
|
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: | 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: | char* filePath;
build_path(filePath,skinDirectory,"MenuBar.png",0);
loadPNGvramfromfileoverwrite(filePath,512,64,(int)testMenuBar_temp); |
Code that crashes:
| Code: | 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: | 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 |
|
| Back to top |
|
 |
Garak
Joined: 27 Jul 2005 Posts: 46
|
Posted: Sun Jan 01, 2006 1:49 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
AnonymousTipster
Joined: 01 Jul 2005 Posts: 197
|
Posted: Sun Jan 01, 2006 8:01 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
urchin
Joined: 02 Jun 2005 Posts: 121
|
Posted: Sun Jan 01, 2006 8:15 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
rinco
Joined: 21 Jan 2005 Posts: 255 Location: Canberra, Australia
|
Posted: Sun Jan 01, 2006 10:45 pm Post subject: |
|
|
| I bet you need to align a parameter or two. The documentation (ie: comments in pspgu.h) describes which parameters need to be aligned. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|