I'm trying to get WiFi code working in my game. Before this the game was running pure usermode and worked perfectly.
Now I'm trying to load the net modules, the game is having errors.
The LoadMainMenu() function is being run correctly, except that if I try and create a new player, or load a previously saved player, the PSP crashes - it's as though file io has stopped working.
Thanks in advance for looking at the code.
Code: Select all
// INCLUDES
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <stdio.h>
#include <pspsdk.h>
#include "graphics.h"
#include <psppower.h>
#include "mainmenu.h"
#include "functions.h"
#include "sound.h"
#include "wifi.h"
// DEFINES
#define RGB(r,g,b) (((r) << 16) | ((g) << 8) | (b))
// GLOBAL VARIABLES
char BornOn[255]; //ADOPTED DATE & TIME
int GreenBarLength[5]; //ARRAY FOR LENGTH OF GREEN BARS
int PlayerFileLines[10]; //NUMBER OF LINES IN THE SAVE FILE
char PlayerName[8]; //PLAYER NAME
char GameSavesName[100][255]; //GAME SAVES NAMES
char TrackName[100][255]; //TRACK NAMES FOR DANCE OFF
Color WhiteColor = RGB(255, 255, 255); //COLOR WHITE
SceCtrlData pad, lastpad; //CONTROLS & OLD CONTROLS
int AddToEnergy = 0; //MODIFIER FOR ENERGY
int AddToHunger = 0; //MODIFIER FOR HUNGER
int AddToFun = 0; //MODIFIER FOR FUN
int AddToHygiene = 0; //MODIFIER FOR HYGIENE
Image* LetterImg[27]; //IMAGES FOR LETTERS
Image* PetIdle; //IMAGE FOR PET NOT BLINKING
Image* PetBlink; //IMAGE FOR PET BLINKING
SceKernelUtilsMt19937Context ctx; //MERSENNE TWISTER FOR RANDOM NUMBERS
int NumPerfectScores[3]; //HOLDER FOR NUMBER OF PERFECT SCORES
int GameTime = 0; //GAME TIME (3600 TO A MINUTE)
// MODULE INFO
PSP_MODULE_INFO("AniMate", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(32); /* smaller stack for kernel thread */
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
WAV_End();
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
// START MAIN
int user_main(SceSize argc, void* argv)
{
SetupCallbacks();
scePowerSetClockFrequency(333, 333, 166); //SOFTWARE DECODING OF MUSIC SLOWS DOWN CPU, UGH!
initGraphics();
//pspAudioInit();
WAV_Init();
int i; //FOR 'FOR' LOOP
char buffer[255]; //CHARACTER BUFFER
//MAIN MENU--NEW GAME LETTERS
extern Image* LetterImg[27];
for (i = 0; i < 27; i++) {
sprintf(buffer, "./Images/Letters/%i.png", i);
LetterImg[i] = Load_Image(buffer);
}
//PET IDLE
extern Image* PetIdle;
PetIdle = Load_Image("./Images/Pet/PetIdle.png");
//PET BLINK
extern Image* PetBlink;
PetBlink = Load_Image("./Images/Pet/PetBlink.png");
while(1)
{
LoadMainMenu();
}
//CLEAN UP ON EXIT
for (i = 0; i < 27; i++)
freeImage(LetterImg[i]);
freeImage(PetIdle);
freeImage(PetBlink);
return 0;
}
int main(void)
{
pspDebugScreenInit();
int err = pspSdkLoadInetModules();
if (err != 0) {
pspDebugScreenPrintf("pspSdkLoadInetModules failed with %x\n", err);
sceKernelDelayThread(5*1000000); // 5 sec to read error
//return 1;
}
// create user thread, tweek stack size here if necessary
SceUID thid = sceKernelCreateThread("User Mode Thread", user_main,
0x11, // default priority
256 * 1024, // stack size (256KB is regular default)
PSP_THREAD_ATTR_USER, NULL);
// start user thread, then wait for it to do everything else
sceKernelStartThread(thid, 0, NULL);
sceKernelWaitThreadEnd(thid, NULL);
sceKernelExitGame();
return 0;
}