SDL_Init - Out of memory

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

Moderators: cheriff, TyRaNiD

Post Reply
FragassRock
Posts: 3
Joined: Fri Oct 19, 2007 8:06 pm

SDL_Init - Out of memory

Post by FragassRock »

Hello everyone,

I try to convert the AtariST emulator 'Hatari' written with SDL on PSP (I have a PSP S&L). Now the program build and run but hang on SDL_Init with an 'out of memory' error...

Here is a small piece of code wich work when builded alone :

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include "SDL.h"

# ifdef PSPFW3X
PSP_MODULE_INFO("SDLHelloWorld", 0x0, 1, 1);
PSP_HEAP_SIZE_KB(6*1024);
# else
PSP_MODULE_INFO("SDLHelloWorld", 0x1000, 1, 1);
# endif
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
PSP_MAIN_THREAD_STACK_SIZE_KB(32);

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define SCREEN_DEPTH 8

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
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;
}

int main(int argc, char *argv[]) {
pspDebugScreenInit();
SetupCallbacks();
pspDebugScreenPrintf("HatariPSP v0.95\n");

SDL_Surface *screen;
SDL_Surface *bmp;
SDL_Rect targetarea;

/* Initialize SDL */
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
pspDebugScreenPrintf("Could not initialize the SDL library:\n %s\n", SDL_GetError() );
sceKernelSleepThread();
return 0;
}

/* Initialize the screen / window */
screen = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE);

/* Load test.bmp */
bmp = SDL_LoadBMP("test.bmp");

/* Draw the image to 10, 20 */
targetarea.x = 0;
targetarea.y = 0;
targetarea.w = bmp->w;
targetarea.h = bmp->h;

SDL_BlitSurface(bmp, NULL, screen, &targetarea);

/* update the screen (aka double buffering) */
SDL_Flip(screen);
sceKernelSleepThread();
}

When I replace the Hatari's main by this one, the error pops. I'm building for a 3.71-2 firmware. I think that the size difference between the two eboot (3MB for Hatari and 390 KB for the test) has some influence...

Does anyone have any clue?
.::Albandu51::.
Posts: 12
Joined: Thu Oct 04, 2007 12:33 am

Post by .::Albandu51::. »

Code: Select all

screen = SDL_SetVideoMode&#40;480, 272, 32, SDL_HWSURFACE | SDL_DOUBLEBUF&#41;;
^^
FragassRock
Posts: 3
Joined: Fri Oct 19, 2007 8:06 pm

Post by FragassRock »

I agree for the SDL_SetVideoMode but the error appears before on the SDL_Init(SDL_INIT_VIDEO)...
aeolusc
Posts: 18
Joined: Sat Oct 14, 2006 12:17 pm

Post by aeolusc »

update to the latest pspsdk and try:

Code: Select all

PSP_HEAP_SIZE_MAX&#40;&#41;;
or

Code: Select all

PSP_HEAP_SIZE_KB&#40;-1&#41;;
FragassRock
Posts: 3
Joined: Fri Oct 19, 2007 8:06 pm

Post by FragassRock »

aeolusc wrote:update to the latest pspsdk and try:

Code: Select all

PSP_HEAP_SIZE_MAX&#40;&#41;;
or

Code: Select all

PSP_HEAP_SIZE_KB&#40;-1&#41;;
Thanks it work!
Post Reply