forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Array problem

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Mon Apr 27, 2009 3:57 am    Post subject: Array problem Reply with quote

I have some strange problems.

Code:
game::game() {
    notenames[1] = "A";
    notenames[2] = "A#";
    notenames[3] = "B";
    notenames[4] = "C";
    notenames[5] = "C#";
    notenames[6] = "D";
    notenames[7] = "D#";
    notenames[8] = "E";
    notenames[9] = "F";
    notenames[10] = "F#";
    notenames[11] = "G";
    notenames[12] = "G#";
    running = true;
}

bool game::run() {   
    while (running) {       
        pspDebugScreenSetXY(0,0);
        pspDebugScreenPrintf("-%s-",notenames[2]);
        for(short i=0;i<5;i++)sceDisplayWaitVblankStart();
    }
    return true;
}


and in the main:
Code:
game GG;
GG.run();


The output has strange behaviour.
The output is:
Code:
-(null)-

And the background had a b=green/blue collor. I always tought that the background collor should be black by default.

Now my question:
What did i do wrong?
I want the output:
Code:
-A#-

_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}


Last edited by jojojoris on Mon Apr 27, 2009 4:22 am; edited 1 time in total
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Mon Apr 27, 2009 4:19 am    Post subject: Reply with quote

what is the type of notename ? String ?
where is the new of the class game?
before your constructor has been called is must been instancied by a new no ?


Last edited by sauron_le_noir on Mon Apr 27, 2009 4:21 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail MSN Messenger
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Mon Apr 27, 2009 4:21 am    Post subject: Reply with quote

sauron_le_noir wrote:
what is the type of notename ? String ?
where is the new of the class GG ?
before your constructor has been called is must been instancied by a new no ?


ooo

Sorry i forget to tell

its a char *

lets say notenames is an array of (char *)
_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Mon Apr 27, 2009 4:28 am    Post subject: Reply with quote

why not using string in your c++ program string type is a object type
char * are pointer used just for compatibility with C

to use your string on operating function like the DebugPrintf just use the c_str() function provide by C++.

With string the compiler can at compile time perform a lot of checks.
on pointer ... it's at runtime and you can have lot of memory leaks ;)

At this site you've got a tuto to write a c++ program on psp

http://www.ghoti.nl/PSPtutorial2.php
Back to top
View user's profile Send private message Send e-mail MSN Messenger
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Mon Apr 27, 2009 7:26 pm    Post subject: Reply with quote

When i use the string type my program crashes and it when i use psp-addr2line is said:
Code:
C:\projects\PSPGuitarHelper>psp-addr2line -e pspgg.elf 0x00002EA0
x:/workspace/minpspw/psp/build/gcc-4.3.3/psp/libstdc++-v3/include/bits/basic_string.h:316


I found out that when i use memset it all works well.
Code:
game::game() {
    memset(notenames,0,18);
    notenames[1] = (char*)"A";
    notenames[2] = (char*)"A#";
    notenames[3] = (char*)"B";
    notenames[4] = (char*)"C";
    notenames[5] = (char*)"C#";
    notenames[6] = (char*)"D";
    notenames[7] = (char*)"D#";
    notenames[8] = (char*)"E";
    notenames[9] = (char*)"F";
    notenames[10] = (char*)"F#";
    notenames[11] = (char*)"G";
    notenames[12] = (char*)"G#";
    running = true;
}


Your site looks usefull. I''m new at object orientating proramming.
_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Tue Apr 28, 2009 4:02 am    Post subject: Reply with quote

variable not initialized = memory leak = fatal error
for the string it is strange i have no problem with it i use list,arrary etc ...
do you have the last toolchain ? and the last gcc ?

Are you compiling under windows -> if yes using the heimdall implementation
of the cygwin one if under linux witch gcc has compile the cross compiler
psp-gcc , is the version of psp-gcc (GCC) -->4.3.2
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group