| View previous topic :: View next topic |
| Author |
Message |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Wed Jan 31, 2007 3:37 pm Post subject: Program Crash on Variable Assignment |
|
|
Hey Guys,
im having the weirdest problem at the moment here it is
this line of code seems to be crashing my program
| Code: | | if (noteMenuArea > 3){noteMenuArea = 0;} |
when used with this if structure
| Code: | if (noteMenuArea == 1)
{
//Some Code
}
if (noteMenuArea == 2)
{
//Some Code
}
if (noteMenuArea == 3)
{
//Some Code
}
if (noteMenuArea == 4)
{
//Some Code
} |
if i change it to something like this
| Code: | | if (noteMenuArea > 0){noteMenuArea = 3;} |
which is logically incorrect for it use the program wont crash
or use this if structure with the first problematic code
| Code: | if (noteMenuArea == 0)
{
//Some Code
}
if (noteMenuArea == 1)
{
//Some Code
}
/*if (noteMenuArea == 2)
{
//Some Code
}
if (noteMenuArea == 3)
{
//Some Code
}*/
|
the last two choices are commented out the line of code up the top works and doesnt crash the program
i cant figure out what is going on here are the error codes i get from psplink
 |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Thu Feb 01, 2007 10:31 am Post subject: |
|
|
| bump |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Thu Feb 01, 2007 10:36 am Post subject: |
|
|
| The exception you are getting is a floating point overflow, are you sure it is crashing on that line or is noteMenuArea a floating point number ? |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Thu Feb 01, 2007 10:52 am Post subject: |
|
|
noteMenuArea is defined as an integer, and im pretty sure its that line but changing the numbers in the if structure or the numbers in the first line of code seem to fix the problem and the program wont crash, but then it doesnt do what i want, if i have the first line correct and set the if structure to this
| Code: | if (noteMenuArea == 0)
{
//Some Code
}
if (noteMenuArea == 2)
{
//Some Code
}
if (noteMenuArea == 3)
{
//Some Code
}
if (noteMenuArea == 4)
{
//Some Code
} |
skipping the one it works also |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Thu Feb 01, 2007 11:01 am Post subject: |
|
|
i just went and tested that last piece of code and nothing is working now
this code here works
| Code: | switch(noteMenuArea)
{
case 0: cellFlag = 1;
menuFlag = 0;
break;
case 1: saveNotes();
checkReminders = 1;
break;
case 2: //deleteNotes();
break;
case 3: //noteExit = 1;
//cellFlag = 1;
//menuFlag = 0;
//actionFlag = 0;
//actionArea = 0;
//noteMenuArea = 0;
break;
} |
with the code in the second two options commented out
but if i uncomment any of it the program crashes again
p.s: is there a way to recover from a crash in psplink without having to restart the psp??
EDIT: okay i think i have the same problem as i had before http://forums.ps2dev.org/viewtopic.php?t=7522 uncommenting say 3 of those variable assignments in the 4th option works, but uncommenting anymore and the program crashes and if i uncomment deleteNotes() with the rest still commented it crashes it seems that too much code crashes my psp, and last time i dint fix anything it jsut worked again by itself after compiling one day[/url] |
|
| Back to top |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
Posted: Thu Feb 01, 2007 11:47 am Post subject: |
|
|
compile with -g, then use psp-addr2line with the EPC adress to find out where it actually crashes.
also for random crashes that have no obvious reason the usual suggestion is to look for alignment problems. _________________ http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/ |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Thu Feb 01, 2007 1:17 pm Post subject: |
|
|
| i have been told that before that it might be alignment problems, but i sill dont quite understand what an alignment problem is and how to fix it |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Feb 01, 2007 4:41 pm Post subject: |
|
|
| You need to provide more of the code... say the entire function that switch is in, and where any global variables used are defined. Simply saying "x++; fails on my program" is impossible to debug by itself. |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Thu Feb 01, 2007 4:45 pm Post subject: |
|
|
almost every variable used within my program is global, but i can post them if you think that would help
this is the function the problematic code is in, and the program runs fine until this code is called then it crashes
| Code: |
void noteSelection()
{
oslReadKeys();
oslSetKeyAutorepeat(OSL_KEYMASK_LEFT|OSL_KEYMASK_RIGHT|OSL_KEYMASK_UP|OSL_KEYMASK_DOWN, 40, 8);
if (osl_keys->pressed.up && menuFlag)
{
noteMenuArea--;
if (noteMenuArea < 0){noteMenuArea = 3;}
}
else if (osl_keys->pressed.down && menuFlag)
{
noteMenuArea++;
if (noteMenuArea > 3){noteMenuArea = 0;}
}
else if (osl_keys->pressed.cross && menuFlag)
{
switch(noteMenuArea)
{
case 0: cellFlag = 1;
menuFlag = 0;
break;
case 1: saveNotes();
checkReminders = 1;
break;
case 2: deleteNotes();
break;
case 3: noteExit = 1;
cellFlag = 1;
menuFlag = 0;
actionFlag = 0;
actionArea = 0;
noteMenuArea = 0;
break;
}
}
else if (osl_keys->held.triangle && cellFlag)
{
menuFlag = 1;
cellFlag = 0;
}
if (cellFlag)
{
keyboard();
}
if (menuFlag && noteMenuArea == 1)
{
oslSetTextColor(textS);
oslPrintf_xy(407, 46, "Note Entry");
oslSetTextColor(textSel);
oslPrintf_xy(406, 45, "Note Entry");
}
else if (menuFlag && noteMenuArea == 2)
{
oslSetTextColor(textS);
oslPrintf_xy(426, 61, "Save");
oslSetTextColor(textSel);
oslPrintf_xy(425, 60, "Save");
}
else if (menuFlag && noteMenuArea == 3)
{
oslSetTextColor(textS);
oslPrintf_xy(419, 76, "Delete");
oslSetTextColor(textSel);
oslPrintf_xy(418, 75, "Delete");
}
else if (menuFlag && noteMenuArea == 4)
{
oslSetTextColor(textS);
oslPrintf_xy(426, 91, "Exit");
oslSetTextColor(textSel);
oslPrintf_xy(425, 90, "Exit");
}
} |
|
|
| Back to top |
|
 |
Tinnus
Joined: 29 Jul 2006 Posts: 67
|
Posted: Thu Feb 01, 2007 9:45 pm Post subject: |
|
|
| reefbarman wrote: | | almost every variable used within my program is global, but i can post them if you think that would help |
That's already bad in itself...
You could, for example, do a tree structure with them using structs (app_data.notes.author for example instead of authornotes).
I'm also under the impression that using structures, alignment problems are less likely to arise. _________________ Let's see what the PSP reserves... well, I'd say anything is better than Palm OS. |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Thu Feb 01, 2007 9:59 pm Post subject: |
|
|
using global variables was one of the easiest ways i could think of having the variables because i needed access to most of them in alot of diffferent functions and didnt want to have to pass stuff through to the functions all,
but with your struct suggestion, your talking about my global variables right like grouping like variables together in structs?? |
|
| Back to top |
|
 |
Cy-4AH
Joined: 31 Jan 2007 Posts: 44 Location: Belarus
|
Posted: Fri Feb 02, 2007 5:01 am Post subject: |
|
|
May be it crashing in deleteNotes()?
Or may be your application multithread and bad values caus bad behavior.
For me it's hard to immagine how changing values of variables can crash programm right in moment when thay changed. |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Fri Feb 02, 2007 9:52 am Post subject: |
|
|
yeah i found it hard to believe as well but i know deleteNotes() works cause its not the only time in the program it is used, the only thing that i can see that crashes it is adding more code to do with variable assignment adding usless code like
allows the program to still work but if option 3 and 4 are filled with the code i need in there it will crash, i believe it is to do with memory alignment but no one seems to be able to really explain what that is or how to fix it,
am i just declaring and initializing my variables in the wrong way should they be in a particular order?? |
|
| Back to top |
|
 |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Fri Feb 02, 2007 10:48 am Post subject: |
|
|
| Quote: | | compile with -g, then use psp-addr2line with the EPC adress to find out where it actually crashes. | Have you done this? It might be time to crack out the dissasembler and see exactly which instruction it is faulting on, and what it is attempting to do... | Quote: | | am i just declaring and initializing my variables in the wrong way should they be in a particular order?? | Hard to say - if thry're global variables and you've only supplied function snippets. With badva being 0, it could be a null dereference somewhere, but then again it's being reported as a fpu exception... _________________ Damn, I need a decent signature! |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Fri Feb 02, 2007 11:02 am Post subject: |
|
|
| groepaz wrote: | | compile with -g, then use psp-addr2line with the EPC adress to find out where it actually crashes. |
okay im not quite sure how to do this, got a quick step by step? i usually use windows for development so im not to savy with linux |
|
| Back to top |
|
 |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Fri Feb 02, 2007 11:23 am Post subject: |
|
|
http://lukasz.dk/programming/playstation-2/ps2link-debugging/ is a link for doing it on ps2 with ps2-link. And the procedure would be almost exactly the same.
Simply add -g to the CCFLAGS (or similar) variable in the makefile, and use psp-addr2line on you elf as explained in the document above.
Unfortunately I am at work right now and cannot dig up more exact instructions without wasting too much time. _________________ Damn, I need a decent signature! |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Fri Feb 02, 2007 11:51 am Post subject: |
|
|
| thank you, i should be able to do it from here ill let you know how i go |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Fri Feb 02, 2007 12:09 pm Post subject: |
|
|
all that psp-addr2line return after i use it on the epc address i get from my crash is ??:0
its not telling me what line at all |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Sat Feb 03, 2007 1:03 am Post subject: |
|
|
| bump |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Sat Feb 03, 2007 1:24 am Post subject: |
|
|
I had such radom crashen when I used some static defined variables (It was really weird to find that bug).
my solution was to declare them as external and define them in a c-file. |
|
| Back to top |
|
 |
Tinnus
Joined: 29 Jul 2006 Posts: 67
|
Posted: Sat Feb 03, 2007 6:03 am Post subject: |
|
|
| reefbarman wrote: | using global variables was one of the easiest ways i could think of having the variables because i needed access to most of them in alot of diffferent functions and didnt want to have to pass stuff through to the functions all,
but with your struct suggestion, your talking about my global variables right like grouping like variables together in structs?? |
Yes.
Also, please stop bumping threads 1 hour after you last post, that's useless and annoying. _________________ Let's see what the PSP reserves... well, I'd say anything is better than Palm OS. |
|
| Back to top |
|
 |
groepaz

Joined: 01 Sep 2005 Posts: 305
|
Posted: Sat Feb 03, 2007 7:19 am Post subject: |
|
|
| reefbarman wrote: | all that psp-addr2line return after i use it on the epc address i get from my crash is ??:0
its not telling me what line at all |
you should try both kernel- and usermode adress, eg when EPC=0xxxxxxx then try 0xxxxxxx and 8xxxxxxx aswell _________________ http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/ |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sat Feb 03, 2007 8:12 am Post subject: |
|
|
| Probably more likely it is crashing in the osl code and that happens not to be built with debugging symbols. I dont recall if osl came with source, if it does you should be able to rebuild with the appropriate -g switch and then rebuild your app. |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Sat Feb 03, 2007 9:53 am Post subject: |
|
|
| Tinnus wrote: |
Also, please stop bumping threads 1 hour after you last post, that's useless and annoying. |
haha if you look carefully its actually about 12 hours in between posts cause 12pm doesnt just turn into 1 am anyways
| Quote: | | you should try both kernel- and usermode adress, eg when EPC=0xxxxxxx then try 0xxxxxxx and 8xxxxxxx aswell | i have tried that and still no luck
| Quote: | | Probably more likely it is crashing in the osl code and that happens not to be built with debugging symbols. I dont recall if osl came with source, if it does you should be able to rebuild with the appropriate -g switch and then rebuild your app. | yeah it does come with the source so i will have to give it a go and see what i can do thanks tyranid |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Sat Feb 03, 2007 9:58 am Post subject: |
|
|
| okay it seems oslib is all just header files and the like and they are all just installed into the pspsdk directory so they just get included in my compiling so i guessing the -g flag will be used for those files when compiling my app yes??? |
|
| Back to top |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sat Feb 03, 2007 3:57 pm Post subject: |
|
|
| Well no, if you dont have the full source to rebuild the libraries with debugging symbols enabled then you wont gain much. Any headers you include will automatically populate the debug symbol table when pulled into code files which are compiled with -g. You'll have to see if the source for osl is actually available. |
|
| Back to top |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Sun Feb 04, 2007 2:02 pm Post subject: |
|
|
| thanks everyone for you help i eventually solved my problem by breaking my code up into mulitple source files and it seemed to work so im on my way to developing again thanks so much |
|
| Back to top |
|
 |
Tinnus
Joined: 29 Jul 2006 Posts: 67
|
Posted: Mon Feb 05, 2007 9:48 am Post subject: |
|
|
| reefbarman wrote: | | Tinnus wrote: |
Also, please stop bumping threads 1 hour after you last post, that's useless and annoying. |
haha if you look carefully its actually about 12 hours in between posts cause
12pm doesnt just turn into 1 am anyways |
Yes, sorry about that :p
But my point is still valid... bumping is bad, especially for a recent topic (1 day old) and in a small forum like this one.
(or at least pretend you're posting something useful ;) _________________ Let's see what the PSP reserves... well, I'd say anything is better than Palm OS. |
|
| Back to top |
|
 |
|