 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
mongatard
Joined: 15 Mar 2006 Posts: 5
|
Posted: Thu Mar 16, 2006 11:02 am Post subject: PSP homebrew crashes |
|
|
| 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. |
|
| Back to top |
|
 |
Viper8896
Joined: 26 Jan 2006 Posts: 110
|
Posted: Thu Mar 16, 2006 12:05 pm Post subject: |
|
|
| u will need to give more details on the problem. like source code, version. then someone might be bale to help |
|
| Back to top |
|
 |
mongatard
Joined: 15 Mar 2006 Posts: 5
|
Posted: Thu Mar 16, 2006 12:11 pm Post subject: |
|
|
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: | #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
{
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;
}objects;
objects skiier;
objects* object;
Image* sprites;
Image* background;
PSP_MODULE_INFO("SkiClone", 0, 1, 1);
int exit_callback(int arg1, int arg2, void *common){
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp){
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void){
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0){
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int getobject(int row1, int column1){
return 0;
}
int getrandom(int low, int high)
{
return (rand() % (high-low+1)) + low;
}
int initobject(int i1){
object[i1].type = getrandom(1,8);
switch(i1){
case 1:
getobject(5,getrandom(1,3));
case 2:
getobject(5,getrandom(4,5));
case 3:
getobject(5,getrandom(6,7));
case 4:
getobject(4,1);
case 5:
getobject(4,getrandom(3,4));
case 6:
getobject(4,getrandom(5,6));
case 7:
getobject(4,8);
case 8:
getobject(7,1);
}
object[i1].picx = row;
object[i1].picy = column;
object[i1].width = objwidth;
object[i1].height = objheight;
object[i1].x = getrandom(1,480 - object[i1].width);
object[i1].y = getrandom(screenheight,screenheight + 250);
object[i1].action = 0;
return 0;
}
int moveobjects(){
for(i = 0;i < numobjects;i++){
if ((object[i].y > 0 && object[i].type == 1) || object[i].type == 2 || object[i].type == 3 || object[i].type == 8){
object[i].x -= directionx;
object[i].y -= directiony;
}
else if ((object[i].y <= 0 && object[i].type == 1) || object[i].type == 2 || object[i].type == 3 || object[i].type == 8){
initobject(i);
object[i].x = getrandom(1,screenwidth);
object[i].y = screenheight;
}
else if (object[i].y > 0 ){
object[i].x -= directionx;
object[i].y -= directiony;
}
else if (object[i].y <= 0){
initobject(i);
}
}
if (height < 0){
getobject(1,1);
object[i].picx = 0;
object[i].picy = 0;
object[i].width = objwidth;
object[i].height = objheight;
}
else if (height > 0){
getobject(1,6);
object[i].picx = row;
object[i].picy = column;
object[i].width = objwidth;
object[i].height = objheight;
directionx = directionx * 1.5;
directiony = directiony * 1.5;
}
return 0;
}
int detectcollisions(){
for(i = 0;i < numobjects;i++){
if (object[i].type == 1 || object[i].type == 4 || object[i].type == 5){
if (skiier.x + skiier.width >= object[i].x && skiier.x <= object[i].x + object[i].width && skiier.y + skiier.height >= object[i].y && skiier.y <= object[i].y + object[i].height && height > object[i].height){
height = -50;
}
}
else if (object[i].type == 2){
if (skiier.x + skiier.width >= object[i].x && skiier.x <= object[i].x + object[i].width && skiier.y + skiier.height >= object[i].y && skiier.y <= object[i].y + object[i].height && height > 0){
height = 50;
}
else if (skiier.x + skiier.width >= object[i].x && skiier.x <= object[i].x + object[i].width && skiier.y + skiier.height >= object[i].y && skiier.y <= object[i].y + object[i].height && height > 0){
height = -50;
}
}
else if (object[i].type == 8){
if (skiier.x + skiier.width >= object[i].x && skiier.x <= object[i].x + object[i].width && skiier.y + skiier.height >= object[i].y && skiier.y <= object[i].y + object[i].height && height == 0){
height = 25;
}
}
else if (object[i].type == 7){
if (skiier.x + skiier.width >= object[i].x && skiier.x <= object[i].x + object[i].width && skiier.y + skiier.height >= object[i].y && skiier.y <= object[i].y + object[i].height && height == 0){
object[i].action = 1;
}
}
}
return 0;
}
int checkkeys(){
int direction;
direction = 0;
if(pad.Lx >= 127 && pad.Ly <= 130){
direction = 1;
}
else if(pad.Lx >= 164 && pad.Ly >= 192){
direction = 2;
}
else if(pad.Lx >= 164 && pad.Ly < 192 && pad.Ly > 130) {
direction = 3;
}
else if(pad.Lx >= 95 && pad.Lx <= 164 && pad.Ly >= 164){
direction = 4;
}
else if(pad.Lx <= 95 && pad.Ly >= 130){
direction = 5;
}
else if(pad.Lx < 63 && pad.Ly <= 130){
direction = 6;
}
else if(pad.Lx <= 127 && pad.Ly <= 130){
direction = 7;
}
else if(pad.Buttons & PSP_CTRL_CROSS){
direction = 8;
}
return (direction);
}
int getkeys(){
if (height == 0){
if(pad.Lx >= 127 && pad.Ly <= 130) {
getobject(1,4);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = 0;
directiony = 0;
}
else if(pad.Lx >= 164 && pad.Ly < 192 && pad.Ly > 130) {
getobject(1,9);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = 7;
directiony = 3;
}
else if(pad.Lx >= 164 && pad.Ly >= 192){
getobject(1,12);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = 5;
directiony = 5;
}
if(pad.Lx >= 95 && pad.Lx <= 164 && pad.Ly >= 164){
getobject(1,8);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = 0;
directiony = 10;
}
else if(pad.Lx <= 95 && pad.Ly >= 130){
getobject(1,9);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = -5;
directiony = 5;
}
else if(pad.Lx < 63 && pad.Ly <= 130){
getobject(1,9);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = -7;
directiony = 3;
}
else if(pad.Lx <= 127 && pad.Ly <= 130){
getobject(1,3);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
directionx = 0;
directiony = 0;
}
if(pad.Buttons & PSP_CTRL_CROSS){
height = 50;
}
}
else if (height > 0){
if(pad.Lx >= 200){
getobject(1,4);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
}
else if (pad.Lx <= 120){
getobject(1,3);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
}
if(pad.Buttons & PSP_CTRL_CROSS){
if (height == 0){
height = 15;
}
else if(height > 0){
if (skiier.action == 0){
skiier.action = 1;
}
else if(skiier.action == 1){
skiier.action = 2;
}
else if(skiier.action == 2){
skiier.action = 0;
}
}
}
}
return 0;
}
int actions(){
if(skiier.action == 1){
getobject(1,6);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
}
else if(skiier.action == 2){
getobject(1,7);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
}
for(i = 0;i < numobjects;i++){
if (object[i].type == 7){
object[i].movex = 0;
object[i].movey = 0;
object[i].action = 3;
getobject(4,7);
object[i].picx = row;
object[i].picy = column;
object[i].width = objwidth;
object[i].height = objheight;
}
}
return 0;
}
int jump(){
if(height > 0){
if (skiier.y < height){
skiier.y = skiier.y - 1;
height --;
}
else if (skiier.y > height){
skiier.y = skiier.y + 1;
height --;
}
}
else if(height < 0){
height ++;
}
return 0;
}
int draw(){
blitAlphaImageToScreen(0, 0, screenwidth, screenheight, background, 0, 0);
for(i = 0;i < numobjects;i++){
if (skiier.y > object[i].y){
blitAlphaImageToScreen(object[i].picx, object[i].picy, object[i].width, object[i].height, sprites, object[i].x, object[i].y);
blitAlphaImageToScreen(skiier.picx,0, skiier.width, skiier.height, sprites, skiier.x, skiier.y);
}
else if (skiier.y < object[i].y){
blitAlphaImageToScreen(object[i].picx, object[i].picy, object[i].width, object[i].height, sprites, object[i].x, object[i].y);
blitAlphaImageToScreen(skiier.picx,0, skiier.width, skiier.height, sprites, skiier.x, skiier.y);
}
}
flipScreen();
return 0;
}
int main(){
sceCtrlReadBufferPositive(&pad, 1);
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
srand(sceKernelLibcTime((void *) 0));
pspDebugScreenInit();
SetupCallbacks();
sprites = loadImage("sprites.png");
background = loadImage("background.png");
getobject(1,4);
skiier.picx = row;
skiier.picy = column;
skiier.width = objwidth;
skiier.height = objheight;
skiier.x = 240 - (skiier.width / 2);
skiier.y = 50;
skiier.action = 0;
for (i = 0; i < numobjects;i++){
initobject(i);
}
while(1){
if (checkkeys() != 0){
getkeys();
}
moveobjects();
detectcollisions();
actions();
jump();
draw();
for(i = 0;i < speed;i++){
}
}
return 0;
} |
|
|
| Back to top |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Thu Mar 16, 2006 7:12 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Thu Mar 16, 2006 7:15 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
mongatard
Joined: 15 Mar 2006 Posts: 5
|
Posted: Thu Mar 16, 2006 10:05 pm Post subject: |
|
|
| 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. |
|
| 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
|