PSP homebrew crashes

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

Moderators: cheriff, TyRaNiD

Post Reply
mongatard
Posts: 5
Joined: Wed Mar 15, 2006 10:11 pm

PSP homebrew crashes

Post by mongatard »

Im making a ski free game for the psp using the toolchain, and every time I try to run it it just crashes and turns off. There don't seem to be any problems with the coding, but when it is run it doesn't work.
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

u will need to give more details on the problem. like source code, version. then someone might be bale to help
mongatard
Posts: 5
Joined: Wed Mar 15, 2006 10:11 pm

Post by mongatard »

Here is the source, as sloppy as it is. I have no idea what is going wrong, it just crashes when started before I do anything. I am kind of a newb when it somes to some of this stuff but I know the basics. I was making a ski free sort of game. What it is supposed to do is turn on, paint a white background to the screen, then paint objects going up as you move down the slope. Sorry if I included too much code, I took out a long function that just made it easier to get an image from my sprite sheet.

Code: Select all

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <png.h>
#include <stdlib.h>
#include <stdio.h>
#include "graphics.h"

int speed = 500000;
int i = 0;
const int screenwidth = 480;
const int screenheight = 272;
int directionx = 0;
int directiony = 0;
int numobjects = 3;
int height = 0;

int objwidth;
int objheight;
int row;
int column;


SceCtrlData pad;

typedef struct
&#123;
	int picx;
	int picy;
	int height;
	int width;
	int x;
	int y;
	int action;
	int movex;
	int movey;
/* type 1 = tree, type 2 = rocks, type 3 = snow type 4 = person */
/* type 5 = snowboarder type 6 = skilift type 7 = dog, type 8 = ramp*/
	int type;
&#125;objects;

objects skiier;
objects* object;

Image* sprites;
Image* background;


PSP_MODULE_INFO&#40;"SkiClone", 0, 1, 1&#41;;

int exit_callback&#40;int arg1, int arg2, void *common&#41;&#123;
   sceKernelExitGame&#40;&#41;;
   return 0;
&#125;

int CallbackThread&#40;SceSize args, void *argp&#41;&#123;
   int cbid;
   
   cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
   sceKernelRegisterExitCallback&#40;cbid&#41;;
   
   sceKernelSleepThreadCB&#40;&#41;;
   
   return 0;
&#125;

int SetupCallbacks&#40;void&#41;&#123;
   int thid = 0;
   
   thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
   if&#40;thid >= 0&#41;&#123;
      sceKernelStartThread&#40;thid, 0, 0&#41;;
   &#125;
   return thid;
&#125;

int getobject&#40;int row1, int column1&#41;&#123;
	
	return 0;
&#125;

int getrandom&#40;int low, int high&#41;
&#123;
    return &#40;rand&#40;&#41; % &#40;high-low+1&#41;&#41; + low;
&#125; 

int initobject&#40;int i1&#41;&#123;
	object&#91;i1&#93;.type = getrandom&#40;1,8&#41;;
	switch&#40;i1&#41;&#123;
		case 1&#58;
			getobject&#40;5,getrandom&#40;1,3&#41;&#41;;
		case 2&#58;
			getobject&#40;5,getrandom&#40;4,5&#41;&#41;;
		case 3&#58;
			getobject&#40;5,getrandom&#40;6,7&#41;&#41;;
		case 4&#58;
			getobject&#40;4,1&#41;;
		case 5&#58;
			getobject&#40;4,getrandom&#40;3,4&#41;&#41;;
		case 6&#58;
			getobject&#40;4,getrandom&#40;5,6&#41;&#41;;
		case 7&#58;
			getobject&#40;4,8&#41;;
		case 8&#58;
			getobject&#40;7,1&#41;;
	&#125;
	object&#91;i1&#93;.picx = row;
	object&#91;i1&#93;.picy = column;
	object&#91;i1&#93;.width = objwidth;
	object&#91;i1&#93;.height = objheight;
	object&#91;i1&#93;.x = getrandom&#40;1,480 - object&#91;i1&#93;.width&#41;;
	object&#91;i1&#93;.y = getrandom&#40;screenheight,screenheight + 250&#41;;
	object&#91;i1&#93;.action = 0;
	return 0;
&#125;

int moveobjects&#40;&#41;&#123;
	for&#40;i = 0;i < numobjects;i++&#41;&#123;
		if &#40;&#40;object&#91;i&#93;.y > 0 && object&#91;i&#93;.type == 1&#41; || object&#91;i&#93;.type == 2 || object&#91;i&#93;.type == 3 || object&#91;i&#93;.type == 8&#41;&#123;
			object&#91;i&#93;.x -= directionx;
			object&#91;i&#93;.y -= directiony;
		&#125;
		else if &#40;&#40;object&#91;i&#93;.y <= 0 && object&#91;i&#93;.type == 1&#41; || object&#91;i&#93;.type == 2 || object&#91;i&#93;.type == 3 || object&#91;i&#93;.type == 8&#41;&#123;
			initobject&#40;i&#41;;
			object&#91;i&#93;.x = getrandom&#40;1,screenwidth&#41;;
			object&#91;i&#93;.y = screenheight;
		&#125;

		else if &#40;object&#91;i&#93;.y > 0 &#41;&#123;
			object&#91;i&#93;.x -= directionx;
			object&#91;i&#93;.y -= directiony;
		&#125;
		else if &#40;object&#91;i&#93;.y <= 0&#41;&#123;
			initobject&#40;i&#41;;
		&#125;
	&#125;
	if &#40;height < 0&#41;&#123;
		getobject&#40;1,1&#41;;
		object&#91;i&#93;.picx = 0;
		object&#91;i&#93;.picy = 0;
		object&#91;i&#93;.width = objwidth;
		object&#91;i&#93;.height = objheight;
	&#125;
	else if &#40;height > 0&#41;&#123;
		getobject&#40;1,6&#41;;
		object&#91;i&#93;.picx = row;
		object&#91;i&#93;.picy = column;
		object&#91;i&#93;.width = objwidth;
		object&#91;i&#93;.height = objheight;
		directionx = directionx * 1.5;
		directiony = directiony * 1.5;
	&#125;
	return 0;
&#125;

int detectcollisions&#40;&#41;&#123;
	for&#40;i = 0;i < numobjects;i++&#41;&#123;
		if &#40;object&#91;i&#93;.type == 1 ||  object&#91;i&#93;.type == 4 || object&#91;i&#93;.type == 5&#41;&#123;
			if &#40;skiier.x + skiier.width >= object&#91;i&#93;.x && skiier.x <= object&#91;i&#93;.x + object&#91;i&#93;.width && skiier.y + skiier.height >= object&#91;i&#93;.y && skiier.y <= object&#91;i&#93;.y + object&#91;i&#93;.height && height > object&#91;i&#93;.height&#41;&#123;
				height = -50;
			&#125;
		&#125;
		else if &#40;object&#91;i&#93;.type == 2&#41;&#123;
			if &#40;skiier.x + skiier.width >= object&#91;i&#93;.x && skiier.x <= object&#91;i&#93;.x + object&#91;i&#93;.width && skiier.y + skiier.height >= object&#91;i&#93;.y && skiier.y <= object&#91;i&#93;.y + object&#91;i&#93;.height && height > 0&#41;&#123;
				height = 50;
			&#125;
			else if &#40;skiier.x + skiier.width >= object&#91;i&#93;.x && skiier.x <= object&#91;i&#93;.x + object&#91;i&#93;.width && skiier.y + skiier.height >= object&#91;i&#93;.y && skiier.y <= object&#91;i&#93;.y + object&#91;i&#93;.height && height > 0&#41;&#123;
				height = -50;
			&#125;
		&#125;
		else if &#40;object&#91;i&#93;.type == 8&#41;&#123;
			if &#40;skiier.x + skiier.width >= object&#91;i&#93;.x && skiier.x <= object&#91;i&#93;.x + object&#91;i&#93;.width && skiier.y + skiier.height >= object&#91;i&#93;.y && skiier.y <= object&#91;i&#93;.y + object&#91;i&#93;.height && height == 0&#41;&#123;
				height = 25;
			&#125;
		&#125;
		else if &#40;object&#91;i&#93;.type == 7&#41;&#123;
			if &#40;skiier.x + skiier.width >= object&#91;i&#93;.x && skiier.x <= object&#91;i&#93;.x + object&#91;i&#93;.width && skiier.y + skiier.height >= object&#91;i&#93;.y && skiier.y <= object&#91;i&#93;.y + object&#91;i&#93;.height && height == 0&#41;&#123;
				object&#91;i&#93;.action = 1;
			&#125;
		&#125;
	&#125;
	return 0;
&#125;

int checkkeys&#40;&#41;&#123;
	int direction;
	direction = 0;
		if&#40;pad.Lx >= 127 && pad.Ly <= 130&#41;&#123; 
			direction = 1;
		&#125; 
		else if&#40;pad.Lx >= 164 && pad.Ly >= 192&#41;&#123; 
			direction = 2;
		&#125;
		else if&#40;pad.Lx >= 164 && pad.Ly < 192 && pad.Ly > 130&#41; &#123; 
			direction = 3;
		&#125; 
		else if&#40;pad.Lx >= 95 && pad.Lx <= 164 && pad.Ly >= 164&#41;&#123; 
			direction = 4;
		&#125; 
		else if&#40;pad.Lx <= 95 && pad.Ly >= 130&#41;&#123; 
			direction = 5;
		&#125;
		else if&#40;pad.Lx < 63 && pad.Ly <= 130&#41;&#123; 
			direction = 6;
		&#125;
		else if&#40;pad.Lx <= 127 && pad.Ly <= 130&#41;&#123; 
			direction = 7;
		&#125;
		else if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
			direction = 8;
		&#125;
		return &#40;direction&#41;;
&#125;
int getkeys&#40;&#41;&#123;
	if &#40;height == 0&#41;&#123;
		if&#40;pad.Lx >= 127 && pad.Ly <= 130&#41; &#123; 
			getobject&#40;1,4&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = 0;
			directiony = 0;
		&#125; 
		else if&#40;pad.Lx >= 164 && pad.Ly < 192 && pad.Ly > 130&#41; &#123; 
			getobject&#40;1,9&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = 7;
			directiony = 3;
		&#125; 
		else if&#40;pad.Lx >= 164 && pad.Ly >= 192&#41;&#123; 
			getobject&#40;1,12&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = 5;
			directiony = 5;
		&#125; 
		if&#40;pad.Lx >= 95 && pad.Lx <= 164 && pad.Ly >= 164&#41;&#123; 
			getobject&#40;1,8&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = 0;
			directiony = 10;
		&#125; 
		else if&#40;pad.Lx <= 95 && pad.Ly >= 130&#41;&#123; 
			getobject&#40;1,9&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = -5;
			directiony = 5;
		&#125;
		else if&#40;pad.Lx < 63 && pad.Ly <= 130&#41;&#123; 
			getobject&#40;1,9&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = -7;
			directiony = 3;
		&#125;
		else if&#40;pad.Lx <= 127 && pad.Ly <= 130&#41;&#123; 
			getobject&#40;1,3&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
			directionx = 0;
			directiony = 0;
		&#125;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
			height = 50;
		&#125;
	&#125;
	else if &#40;height > 0&#41;&#123;
		if&#40;pad.Lx >= 200&#41;&#123; 
			getobject&#40;1,4&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
		&#125;
		else if &#40;pad.Lx <= 120&#41;&#123;
			getobject&#40;1,3&#41;;
			skiier.picx = row;
			skiier.picy = column;
			skiier.width = objwidth;
			skiier.height = objheight;
		&#125;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;&#123;
			if &#40;height == 0&#41;&#123;
				height = 15;
			&#125;
			else if&#40;height > 0&#41;&#123;
				if &#40;skiier.action == 0&#41;&#123;
					skiier.action = 1;
				&#125;
				else if&#40;skiier.action == 1&#41;&#123;
					skiier.action = 2;
				&#125;
				else if&#40;skiier.action == 2&#41;&#123;
					skiier.action = 0;
				&#125;
			&#125;
		&#125;

	&#125;
	return 0;
&#125;

int actions&#40;&#41;&#123;
	if&#40;skiier.action == 1&#41;&#123;
		getobject&#40;1,6&#41;;
		skiier.picx = row;
		skiier.picy = column;
		skiier.width = objwidth;
		skiier.height = objheight;
	&#125;
	else if&#40;skiier.action == 2&#41;&#123;
		getobject&#40;1,7&#41;;
		skiier.picx = row;
		skiier.picy = column;
		skiier.width = objwidth;
		skiier.height = objheight;
	&#125;

	for&#40;i = 0;i < numobjects;i++&#41;&#123;
		if &#40;object&#91;i&#93;.type == 7&#41;&#123;
			object&#91;i&#93;.movex = 0;
			object&#91;i&#93;.movey = 0;
			object&#91;i&#93;.action = 3;
			getobject&#40;4,7&#41;;
			object&#91;i&#93;.picx = row;
			object&#91;i&#93;.picy = column;
			object&#91;i&#93;.width = objwidth;
			object&#91;i&#93;.height = objheight;
		&#125;
	&#125;
	return 0;
&#125;

int jump&#40;&#41;&#123;
	if&#40;height > 0&#41;&#123;
		if &#40;skiier.y < height&#41;&#123;
			skiier.y = skiier.y - 1;
			height --;
		&#125;
		else if &#40;skiier.y > height&#41;&#123;
			skiier.y = skiier.y + 1;
			height --;
		&#125;
	&#125;
	else if&#40;height < 0&#41;&#123;
		height ++;
	&#125;
	return 0;
&#125;

int draw&#40;&#41;&#123;
	blitAlphaImageToScreen&#40;0, 0, screenwidth, screenheight, background, 0, 0&#41;;
	for&#40;i = 0;i < numobjects;i++&#41;&#123;
		if &#40;skiier.y > object&#91;i&#93;.y&#41;&#123;
			blitAlphaImageToScreen&#40;object&#91;i&#93;.picx, object&#91;i&#93;.picy, object&#91;i&#93;.width, object&#91;i&#93;.height, sprites, object&#91;i&#93;.x, object&#91;i&#93;.y&#41;;
			blitAlphaImageToScreen&#40;skiier.picx,0, skiier.width, skiier.height, sprites, skiier.x, skiier.y&#41;;
		&#125;
		else if &#40;skiier.y < object&#91;i&#93;.y&#41;&#123;
			blitAlphaImageToScreen&#40;object&#91;i&#93;.picx, object&#91;i&#93;.picy, object&#91;i&#93;.width, object&#91;i&#93;.height, sprites, object&#91;i&#93;.x, object&#91;i&#93;.y&#41;;
			blitAlphaImageToScreen&#40;skiier.picx,0, skiier.width, skiier.height, sprites, skiier.x, skiier.y&#41;;
		&#125;
	&#125;
	flipScreen&#40;&#41;;
	return 0;
&#125;

int main&#40;&#41;&#123;	

	sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
	sceCtrlSetSamplingCycle&#40;0&#41;; 
	sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;; 

	srand&#40;sceKernelLibcTime&#40;&#40;void *&#41; 0&#41;&#41;; 
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;

	sprites = loadImage&#40;"sprites.png"&#41;;
	background = loadImage&#40;"background.png"&#41;;

	getobject&#40;1,4&#41;;
	skiier.picx = row;
	skiier.picy = column;
	skiier.width = objwidth;
	skiier.height = objheight;
	skiier.x = 240 - &#40;skiier.width / 2&#41;;
	skiier.y = 50;
	skiier.action = 0;
	for &#40;i = 0; i < numobjects;i++&#41;&#123;
		initobject&#40;i&#41;;
	&#125;
	while&#40;1&#41;&#123;
		if &#40;checkkeys&#40;&#41; != 0&#41;&#123;
			getkeys&#40;&#41;;
		&#125;
		moveobjects&#40;&#41;;
		detectcollisions&#40;&#41;;
		actions&#40;&#41;;
		jump&#40;&#41;;
		draw&#40;&#41;;
		for&#40;i = 0;i < speed;i++&#41;&#123;
		&#125;
	&#125;
	return 0;
&#125;
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

First rule in debugging... start small, and slowly add code until you can reproduce the problem.

Take out all of your code that does stuff, and get it so you can run. You probably have a divide by zero or you're accessing an invalid memory address.
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

I just noticed that you never intialize "object". Its a global pointer so its pointing at NULL.

You need to do:

object = new objects[numobjects];

Also, you're naming of object and objects is backwards, you should switch them so each item is an object, and the collection is objects.
mongatard
Posts: 5
Joined: Wed Mar 15, 2006 10:11 pm

Post by mongatard »

I know I should have sterted small and worked up, but I had a psp when I started, then it got stolen so most of this was coded after my psp was gone. I am borrowing one now until I get a new one. I seem to have narrowed it down to my typedef. Everytime this part of the code is run it crashes.
Post Reply