Program Crash on Variable Assignment

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Program Crash on Variable Assignment

Post by reefbarman »

Hey Guys,

im having the weirdest problem at the moment here it is

this line of code seems to be crashing my program

Code: Select all

if (noteMenuArea > 3){noteMenuArea = 0;}
when used with this if structure

Code: Select all

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: Select all

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: Select all

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


Image
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

bump
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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 ?
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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: Select all

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
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

i just went and tested that last piece of code and nothing is working now

this code here works

Code: Select all

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]
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

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.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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: Select all

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 &#40;noteMenuArea < 0&#41;&#123;noteMenuArea = 3;&#125;
	&#125;
	else if &#40;osl_keys->pressed.down && menuFlag&#41;
	&#123;
			noteMenuArea++;
			if &#40;noteMenuArea > 3&#41;&#123;noteMenuArea = 0;&#125;
	&#125;
	else if &#40;osl_keys->pressed.cross && menuFlag&#41;
	&#123;	
		switch&#40;noteMenuArea&#41;
		&#123;
		case 0&#58;		cellFlag = 1;
					menuFlag = 0;
					break;
		case 1&#58;		saveNotes&#40;&#41;;
					checkReminders = 1;
					break;
		case 2&#58;		deleteNotes&#40;&#41;;
					break;
		case 3&#58;		noteExit = 1;
					cellFlag = 1;
					menuFlag = 0;
					actionFlag = 0;
					actionArea = 0;
					noteMenuArea = 0;
					break;
		&#125;
	&#125;
	else if &#40;osl_keys->held.triangle && cellFlag&#41;
	&#123;
		menuFlag = 1;
		cellFlag = 0;
	&#125;

	if &#40;cellFlag&#41;
	&#123;
		keyboard&#40;&#41;;	
	&#125;

	if &#40;menuFlag && noteMenuArea == 1&#41;
	&#123;
		oslSetTextColor&#40;textS&#41;;
		oslPrintf_xy&#40;407, 46, "Note Entry"&#41;;
		oslSetTextColor&#40;textSel&#41;;
		oslPrintf_xy&#40;406, 45, "Note Entry"&#41;;
	&#125;
	else if &#40;menuFlag && noteMenuArea == 2&#41;
	&#123;	
		oslSetTextColor&#40;textS&#41;;
		oslPrintf_xy&#40;426, 61, "Save"&#41;;
		oslSetTextColor&#40;textSel&#41;;
		oslPrintf_xy&#40;425, 60, "Save"&#41;;
	&#125;
	else if &#40;menuFlag && noteMenuArea == 3&#41;
	&#123;
		oslSetTextColor&#40;textS&#41;;
		oslPrintf_xy&#40;419, 76, "Delete"&#41;;
		oslSetTextColor&#40;textSel&#41;;
		oslPrintf_xy&#40;418, 75, "Delete"&#41;;
	&#125;
	else if &#40;menuFlag && noteMenuArea == 4&#41;
	&#123;
		oslSetTextColor&#40;textS&#41;;
		oslPrintf_xy&#40;426, 91, "Exit"&#41;;
		oslSetTextColor&#40;textSel&#41;;
		oslPrintf_xy&#40;425, 90, "Exit"&#41;;
	&#125;
&#125;
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

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.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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??
Cy-4AH
Posts: 44
Joined: Wed Jan 31, 2007 9:58 pm
Location: Belarus

Post by Cy-4AH »

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.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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

Code: Select all

if&#40;1&#41;&#123;1==1&#125;;
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??
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

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...
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!
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

http://lukasz.dk/programming/playstatio ... 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!
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

thank you, i should be able to do it from here ill let you know how i go
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

bump
rapso
Posts: 140
Joined: Mon Mar 28, 2005 6:35 am

Post by rapso »

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.
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

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.
User avatar
groepaz
Posts: 305
Joined: Thu Sep 01, 2005 7:44 am
Contact:

Post by groepaz »

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
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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
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
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
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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???
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
reefbarman
Posts: 87
Joined: Mon Jan 08, 2007 12:16 pm
Location: Australia

Post by reefbarman »

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
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

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.
Post Reply