OK,
After many tests, It seems C++ is not being initialized properly or something is seriously wrong. Doing the exact same stuff in C works perfect, but in C++ has many errors and crashes on the PSP. Can someone please help and maybe we can get C++ working well on this.
Has anyone really tested C++ working on this platform, not just C?
Thanks
Jeff.
C++ not working well
Here's the code I used:
When we call the functions for reading the file directly in C it works fine. As soon as we start to make a class and compile using the stdc++ lib we crash. We also are seeing some weird stuff with C++ in general. I was hoping someone can test or get working a C++ example, I think it would help out our community very nicely, not just me :)
Thanks again guys,
Jeff.
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2005 Jesper Svennevid
*/
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
PSP_MODULE_INFO("Lights Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
int SetupCallbacks();
static unsigned int __attribute__((aligned(16))) list[262144];
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4) /* change this if you change to another screenmode */
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */
volatile int g_exit=0;
class TestLogger
{
public:
TestLogger() { };
~TestLogger() { };
void Log() {FILE *file,*file2;
file = fopen("ms0:/PSP/GAME/logtest.txt", "wb");
file2 = fopen("ms0:/PSP/GAME/logtest2.txt", "wb");
fwrite("test data\n", 1, 10, file);
fwrite("test data\n", 1, 10, file2);
fclose(file);
fclose(file2);
};
};
int main(int argc, char* argv[])
{
FILE *file;
FILE *file2;
SetupCallbacks();
sceKernelDcacheWritebackAll();
pspDebugScreenInit();
//sceGuStart(GU_DIRECT,list);
//sceGuInit();
pspDebugScreenPrintf("init logger\n");
//logger.Log();
//g_logger.Init("ms0:/PSP/GAME/log.txt");
//pspDebugScreenPrintf("init content\n");
//g_ContentManager.Init("ms0:/PSP/GAME");
//g_logger.Log(Logger::LL_INFO,"TEST","TEST ");
//g_logger.SetLog( NULL);
pspDebugScreenPrintf("write test file\n");
file = fopen("ms0:/PSP/GAME/logtest.txt", "wb");
file2 = fopen("ms0:/PSP/GAME/logtest2.txt", "wb");
fwrite("test data\n", 1, 10, file);
fwrite("test data\n", 1, 10, file2);
fclose(file);
fclose(file2);
while (g_exit==0)
{
/*sceGuStart(GU_DIRECT,list);
sceGuClearColor(0x554433);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();*/
}
//sceGuTerm();
sceKernelExitGame();
return 0;
}
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
//sceKernelExitGame();
g_exit=1;
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;
}
Thanks again guys,
Jeff.
Where does it crash? What type of exception is it? What function does it crash in (psp-objdump -d or psp-addr2line can be of great help here)? Can you provide a slimmed-down piece of code that causes the crash (the code you posted doesn't look complete enough for someone else to repro it)?webjeff wrote:When we call the functions for reading the file directly in C it works fine. As soon as we start to make a class and compile using the stdc++ lib we crash. We also are seeing some weird stuff with C++ in general.
No one has reported any strangeness using C++, but it's possible there's something going on in the tools. We need a better idea of what's happening though :).
I've had many problems with C++ in the past.
First Step, make sure you have the lastest toolchain.
Second Step, modify the Make file. Add these lines
USE_PSPSDK_LIBC = 1
CFLAGS = -O2 -G0 -Wall
Should work fine.
Also, if you still have problems add
extern "C" {
//Code
};
here example of Makefile
To test this out, try running the sdk/gu/copy/ app. modify the Makefile. and add a basic class in the copy.cpp file.
heres a example of code that is writting in C++ for the PSP, compiles fine, and works fine on the psp
http://tmpstore.free.fr/FileAssistant/v ... c.php?t=21
edit:
I've also tried this with the Light project, works perfectly fine. let me know if you have any problems.
First Step, make sure you have the lastest toolchain.
Second Step, modify the Make file. Add these lines
USE_PSPSDK_LIBC = 1
CFLAGS = -O2 -G0 -Wall
Should work fine.
Also, if you still have problems add
extern "C" {
//Code
};
here example of Makefile
Code: Select all
TARGET = copy
OBJS = copy.o
INCDIR =
CFLAGS = -02 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
USE_PSPSDK_LIBC = 1
LIBDIR =
LDFLAGS =
LIBS= -lpspgum -lpspgu -lm
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = CopyImage Sample
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
Code: Select all
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <pspgu.h>
#ifndef __cplusplus
extern "C"
{
#endif
PSP_MODULE_INFO("CopyImage Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
class test
{
public:
void hey();
};
void test::hey() { }
....
....
....
int main(int argc, char**argv)
{
test *t=new test;
t->hey();
...
}
...
....
#ifndef __cplusplus
}; //end extern "C"
#endif
http://tmpstore.free.fr/FileAssistant/v ... c.php?t=21
edit:
I've also tried this with the Light project, works perfectly fine. let me know if you have any problems.
There are 10 types of people in the world: Those who understand binary, and those who don't...