I'm in big trouble with malloc(). I had a PSP project up and running which was allocating several hundreds of kilobytes. I loaded jpgs, a truetupe font, music and so on.
But from yesterday on, almost all my malloc() calls fail. It is no longer possible to allocate 64k or more. I installed a brand new toolchain and PSPSDK, but no luck. I tried to hunt down the problem with reducing the code to a minimum, and here is the essence of what is failing:
malloc-test.c
Code: Select all
#include <pspkernel.h>
#include <stdlib.h>
#include <stdio.h>
#include <pspctrl.h>
PSP_MODULE_INFO("hexxpipes", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
int g_ExitApplication = 0; // global exit flag, app runs until this is != 0
int exit_callback(int arg1, int arg2, void *common)
{
// set our global exit flag
g_ExitApplication = 1;
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;
// create thread
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11,
0xFA0, 0, 0);
// start thread
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int InitApplication(int argc, char** argv)
{
SceCtrlData pad, lastpad;
int i = 0;
char *c;
printf("\nStarting...\n");
SetupCallbacks();
sceCtrlReadBufferPositive(&lastpad, 1);
do
{
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons != lastpad.Buttons)
{
if(pad.Buttons & PSP_CTRL_CROSS)
{
c = (char*)malloc(8192); i+=8;
if(c) printf("malloc ok, %i k allocated\n", i);
else printf("malloc failed\n");
}
lastpad = pad;
}
} while(!((pad.Buttons & PSP_CTRL_START) || g_ExitApplication));
sceKernelExitGame();
return 0;
}
int main(int argc, char** argv)
{
InitApplication(argc, argv); // defined in PSP/pspInit.h and win32/win32Init.h
return 0;
}
Code: Select all
TARGET = malloc-test
PRX_EXPORTS=exports.exp
BUILD_PRX=1
OBJS = malloc-test.o
CFLAGS = -O2 -G0 -Wall
LIBS =
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti -fno-strict-aliasing
ASFLAGS = $(CFLAGS)
PSPSDK= $(shell psp-config --pspsdk-path)
PSPDIR= $(shell psp-config --psp-prefix)
include $(PSPSDK)/lib/build.mak
Code: Select all
PSP_BEGIN_EXPORTS
PSP_EXPORT_START(syslib, 0, 0x8000)
PSP_EXPORT_FUNC(module_start)
PSP_EXPORT_VAR(module_info)
PSP_EXPORT_END
PSP_END_EXPORTS
Any help would be greatly appreciated. I'm really lost.
Thoralt