anyone saw the error in my code yet?
Printable View
anyone saw the error in my code yet?
Have you, oh, I don't know, tried running it in PSPLink so you can find out where it crashed? That's generally helpful information.
That is what auto completion is for in text editors and IDEs.Zitat:
Zitat von youresam
From: http://www.psp-programming.com/forum...p?topic=2161.0
Zitat:
Zitat von Yeldarb
i dont have a psp:(Zitat:
Zitat von Archaemic
Or just set up an exception handler and use psp-addr2line? Would be much more helpful :rolleyes:Zitat:
Zitat von Archaemic
That's also helpful if you're writing a kernel mode application, I guess. Although--
Um...then how are you testing this?Zitat:
Zitat von hallo007
friends / beta testers
i found out it crashes here:
anyone see something?Code:while(1)
{
blitImage(0 , 0 , desktopBack);//wallpaper
for(unsigned int loop = 0; loop < sizeof(fileList); loop++ )
{
char buffer[10];
y += 10; //go away from the file name
if(sizeof(fileList[loop]) > 10)
{
strncpy(buffer , fileList[loop].c_str() , sizeof(buffer) - 3);
strcat(buffer , "..");
fileBuffer[loop] = buffer;
}
else
{
fileBuffer[loop] = fileList[loop];
}
if(isFile(fileList[loop]))
{
blitImage(x , y ,iconExample);
}
else
{
blitImage(x , y ,iconFolder);
}
y += 40;
printg(x , y , fileBuffer[loop].c_str() , white);
if(y > 249)
{
x += 108;
y = 10;
}
}
Did you try any debugging methods?
If it doesn't compile right it's because you are declaring the unsigned int loop in the for statement. In C, you have to declare it out of or right before the for statement like this:Zitat:
Zitat von hallo007
Code:unsigned int loop;
for(loop = 0; loop<whatever;loop++)
{
}
Take a look at the code for a moment and you'll see this: "fileBuffer[loop].c_str()". He's using STL strings, which means that this is C++, therefore it's valid. Also, he said it was crashing, which means it must be compiling.
E] Wait, where's buffer defined?
E2] Nevermind, I see it now.
string fileBuffer[222]; ?
no i dindt tried the debugging methods because i havent got a psp and my friends havent got cygwin or the knowledge to use it
...
Member that little lesson we gave you on using #define, #ifdef, and #ifndef to debug?
o yeah , wait it is a few pages back
i thought you mean psplink;-)
-= Double Post =-
#define DEBUG
#ifdef DEBUG
...
#endif
but what is this gong to help? :p
This is terribly unsafe. If you're going to strcat it, at least make sure to memset buffer to 0 first, otherwise you'll have an instant buffer overflow right there.Code:char buffer[10];
y += 10; //go away from the file name
if(sizeof(fileList[loop]) > 10)
{
strncpy(buffer , fileList[loop].c_str() , sizeof(buffer) - 3);
strcat(buffer , "..");
fileBuffer[loop] = buffer;
}
sizeof(buffer) - 3
i reserved two bytes for the ".."
You are using C++ strings dammit. Use C++ string operations !!
http://www.cppreference.com/cppstring/append.html
-= Double Post =-
This does not work C++ strings are objects and hold extra data besides the actual char string.Code:if(sizeof(fileList[loop]) > 10)
http://www.cppreference.com/cppstring/length.html
That's not where the overflow is coming from. The overflow is coming from the fact that the memory allocated is not necessarily all 0. It could be a (seemingly) random string of characters.Zitat:
Zitat von hallo007
Are you serious?Zitat:
Zitat von hallo007
yes I am
thnx yauster , i take a look
Why can no one spell yaustar? Honestly, it's not that hard to remember.
Anyway, you'd use the conditionals to print stuff out in debug mode so you can isolate the crash. No PSPLink necessary. It's tedious, but it works.
thats an explenation (y)
thnx yaustar
I ported it:
Code:if(fileList[loop].size() > 10)
{
fileBuffer[loop].clear();
fileBuffer[loop].append( fileList[loop], 0 , 10);
fileBuffer[loop].append( 2, '.' );
}
Something tells me that's not going to work very well. Maybe it's the clearing and then appending itself with itself (even though it's empty). I dunno.
dude
fileBuffer[loop].append( fileList[loop], 0 , 10);
they are two differnt variabels
...oh.
I feel stupid now.
ok i'm trying to add a multi array to my function yest i'm unsure how i've been trying:
object update(float** object_vertex_array,int max_vertexs,int frame_to){
object update(float **object_vertex_array,int max_vertexs,int frame_to){
object update(float *object_vertex_array[],int max_vertexs,int frame_to){
object update(float *object_vertex_array,int max_vertexs,int frame_to){
yet for the first 3 i always get the following error:
./main.cpp: In function 'int main(int, char**)':
./main.cpp:61: error: cannot convert 'float (*)[3]' to 'float**' for argument '1
' to 'object update(float**, int, int)'
make: *** [main.o] Error 1
and i call it like:
test_object_float[0][1]=0.0f;
test_object_float[0][2]=1.0f;
test_object_float[0][3]=0.0f;
test_object_float[1][1]=1.0f;
test_object_float[1][2]=-1.0f;
test_object_float[1][3]=0.0f;
test_object_float[2][1]=-1.0f;
test_object_float[2][2]=-1.0f;
test_object_float[2][3]=0.0f;
test_object = update(test_object_float, numOfTriangles,1);
test_object = update(test_object_float[3],numOfTriangles,1);
the second way gives me the following error:
./main.cpp: In function 'int main(int, char**)':
./main.cpp:61: error: cannot convert 'float*' to 'float**' for argument '1' to '
object update(float**, int, int)'
*ick* Now we start running into problems
Note: This is dangerous and possibly undefined behaviour.Code:#include <stdio.h>
void aFunction( float * anArray )
{
printf( "%f\n", anArray[0] ); // same as [0][0]
printf( "%f\n", anArray[3] ); // same as [1][0]
}
int main(int argc, char* argv[])
{
float blah[3][3] = { { 0.0f, 1.0f, 2.0f},
{ 3.0f, 4.0f, 5.0f },
{ 6.0f, 7.0f, 8.0f }} ;
float * apBLah = (float *)(blah);
aFunction( apBLah );
return 0;
}
thxs yaustar but i still get this error:
/main.o
./main.cpp: In function 'int main(int, char**)':
./main.cpp:62: error: cannot convert 'float*' to 'float**' for argument '1' to '
object update(float**, int, int)'
./functions/update_object.txt: In function 'object update(float*, int, int)':
./functions/update_object.txt:8: error: invalid types 'float[int]' for array sub
script
./functions/update_object.txt:9: error: invalid types 'float[int]' for array sub
script
./functions/update_object.txt:10: error: invalid types 'float[int]' for array su
bscript
make: *** [main.o] Error 1
i've been looking around for an answer and none have worked so i'm beginning to think that you can't pass a multi array into a function(which is odd)
edit: i figured it out i changed:
(float *)(blah)
to
(float **)(blah)
My posted code compiles straight off. If you are using this, then you have applied the concept incorrectly. You can't pass a multi-dimension static sized array due to the way that the memory is laid out. That is why I converted it to a one dimensional array before passing it to a function.
nvm i found out what i was doing and no longer need that as i like to declare my functions after my main function so i called the function earlier in the program and forgot to go back and change that now it's working=-)
Hi! :)
I'm a noob and I have a noob question for you. :)
I searched the forum but didn't find any answer.
I have a problema with the function sceDisplaySetBrightness.
The first time I try to execute it my program hangs and returns to the dashboard.
Can someone help me, please?
Here's my code:
Many thanks. :)Code:#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <psppower.h>
PSP_MODULE_INFO("Brightness Test ", 0x1000, 1, 1);
void sceDisplay_driver_9E3C6DC6(int a0,int a1);//a0 0-100,a1 = 0/1 (set to 0)
#define sceDisplaySetBrightness sceDisplay_driver_9E3C6DC6
void sceDisplay_driver_31C4BAA8(int *a0,int *a1);
#define sceDisplayGetBrightness sceDisplay_driver_31C4BAA8
// TWILIGHT ZONE! <do doo do doo>
/* 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;
}
// END OF TWILIGHT ZONE! <do doo do do>
int main() {
scePowerSetClockFrequency(222, 222, 111);
pspDebugScreenInit();
SetupCallbacks();
int curBrightness = 0;
SceCtrlData pad;
curBrightness = 100;
pspDebugScreenSetTextColor(0xffffff);
pspDebugScreenSetBackColor(0x000000);
pspDebugScreenInit();
pspDebugScreenSetXY(0, 23);
pspDebugScreenPrintf("Press L or R to change brightness");
pspDebugScreenSetXY(0, 24);
pspDebugScreenPrintf("Press TRIANGLE to exit");
while(1) {
pspDebugScreenSetXY(0, 15);
pspDebugScreenPrintf("Current brightness: %i", curBrightness);
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_LTRIGGER) {
if (curBrightness > 0){
curBrightness--;
sceDisplaySetBrightness(curBrightness, 0);
}
}else if(pad.Buttons & PSP_CTRL_RTRIGGER) {
if (curBrightness < 100){
curBrightness++;
sceDisplaySetBrightness(curBrightness, 0);
}
}else if(pad.Buttons & PSP_CTRL_TRIANGLE) {
break;
}
sceKernelDelayThread(100000);
}
sceKernelExitGame();
return(0);
}
Ciaooo
Sakya
since when ?Zitat:
Zitat von yaustar
Surely,
that works no ? cos my programs let me ?Code:void functionName(int array [][10])
{
//Code goes here
}
Sorry, I meant to add "via pointer to a pointer".Zitat:
Zitat von MiG
Code:void function( int ** anArray )
{
// This won't work if you pass a statically sized array
}
void function( int anArray[10][10] )
{
// This will work as expected as long as the size of the arrays are correct
}
can you set it to 100? isnt 4 the maximum?Zitat:
Zitat von sakya
Hi! :)
The first parameter is 0-100:Zitat:
Zitat von hallo007
:)Code:void sceDisplay_driver_9E3C6DC6(int a0,int a1);//a0 0-100,a1 = 0/1 (set to 0)
Ciaooo
Sakya
sceKernelDelayThread(1000 00);
is in your while loop , you will be able to push a button for 0,00000000000000000000000 0000000000000001 seconds :P
use it like this ;-)
understand? feel free to ask questions;-)Code:if (curBrightness < 100)
{
curBrightness++;
sceDisplaySetBrightness(curBrightness, 0);
sceKernelDelayThread(100000);
}
Hi! :)
Many thanks for your reply. :)
Oooops, many thanks. ;)Zitat:
Zitat von hallo007
I fixed this by moving the sceKernelDelayThread() after sceDisplaySetBrightness() , but the program keeps hanging when I press L to change brightness. :(
Ciaooo
Sakya
I need some help. How do you play a pmf file? Is there a library with a tutorial to download?
Seen as sceKernelDelayThread(1000 0); will delay your program for a lonnng time, i think its 10s ? i don't know how the delays work on the PSP, but if its milliseconds, it will delay your app for 10s. Change it to something like 100, its just to stop the user from frantically changing the settings.Zitat:
Zitat von sakya
MiG
no
1000000 is 1 second ;-)
Yeah, sceKernelDelayThread takes the time to wait as microseconds.Zitat:
Zitat von hallo007
BTW, I'm having trouble with building PSPlink & psplinkusb with the new toolchain. If anyone has the PC side binaries for Ubuntu and would like to share them, please PM me :)