Illegal exception in 2.62 (SOLVED)

Started by Etcher Squared Games, Sun 19/06/2005 23:36:23

Previous topic - Next topic

Etcher Squared Games

The error text:

Code: ags

---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occured in ACWIN.EXE at EIP = 0x00449B6D ; program pointer is +6, ACI version 2.62.772, gtags (2,5)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and notify CJ on the Tech forum.

(Global script line 81)


Most versions of Windows allow you to press Ctrl+C now to copy this entire message to the clipboard for easy reporting.
---------------------------
OK   
---------------------------



The code in question:
Code: ags




int tot_invcursors = 338;
mystring invcursors[338];  // 13 cursors * 26 inventory = 338  not all cursors used
string out_invcursors;
function GetInvCursor(int cursor, int inv)
{
  int index = (cursor * INV_COUNT) + inv;
  Display("index: %d  cursor: %d  inv: %d  count: %d", index, cursor, inv, INV_COUNT); 
    Display(invcursors[index].s);
  Display("dddd   '%s'", invcursors[index].s);
  if ((index >= tot_invcursors) || (index < 0))
  {
    StrCopy(out_invcursors, "");  
  }  
  else
  {
    StrCopy(out_invcursors, invcursors[index].s);      // this is line 81
  }  
}
function SetInvCursor(int cursor, int inv, string text)
{
  int index = (cursor * INV_COUNT) + inv;
  StrCopy(invcursors[index].s, text);
}




I'm using an array to store my "descriptions" of items.  This in particular is for when you click a cursor on an inventory item.

(The display's in the code where my futile attempts to debug myself.)

What is funny, is I have the exact same thing in a room (the above code is in my global)....

the room code in question
Code: ags




int tot_desc = 221;
mystring descs[221];  // 13 cursors * 17 objects = 208  not all cursors used
string out_desc;
function GetDesc(int cursor, int object)
{
  int index = (cursor * obj_num) + object;
  if (index >= tot_desc)
    StrCopy(out_desc, "");  
  else
    StrCopy(out_desc, descs[index].s);  
}
function SetDesc(int cursor, int object, string text)
{
  int index = (cursor * obj_num) + object;
  StrCopy(descs[index].s, text);
}


THIS WORKS!!!
This is used when you click on something in the room and I grab the description.

Each function has its own string that is used as the "out" variable.

It compiles and plays fine otherwise.  I tried upgrading it to 2.7, but I got loads of import errors. Something like "internal script error, this should not happen".

I don't have the exact text of that, but if you like I can re-try importing it into 2.7.   I'm sticking with 2.62 because I started the project with that version (and 2.7 was just a gleam in CJ's eyes)

Oh yeah, almost forgot, inside my header...

Code: ags



struct mystring 
{
  char s[200];
};



As instructed by Strazer in some thread about multidemensional arrays.

The code provided here is NOT as there is in each file.  So, if you want the whole thing, like the header file, please ask and I'll provide.

Also, if there is a thread about this that I simply missed, please point me in that direction.

Thank you.



[EDIT]
OK, forgot to mention what I was actually doing...

This error occurs when I click an icon, on one of my inventory.
I do have the "handle inventory clicks in script" checked if that matters at all?



website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

Pumaman

Did the Display() statements that you put in display the correct values just before it crashed?

Etcher Squared Games

The first display displayed the correct Numbers in terms of the cursor, and item and the math expected.

The 2nd display never displayed, which means that the value is blank, which it SHOULDN'T be....

the 3rd display just gives "ddddÃ,  Ã,  Ã,  "



[MAJOR EDIT!!!!]
I just got it working, but I don't understand why the mistake I did would cause the above error...

Being a welled trained professional programmer, I've learned to initialize my variables even if not always needed.....

I have a function in my global called SetInvCursor()Ã,  which is used to set the output descript of when you click a cursor on an inventory item.

I also have a function called SetInvInv() which is used in the special case of using inventory on inventory.

One of the first things I did in my StartGame function is to init my InvCursorStructure..
Code: ags


Ã,  int cur = CUR_COUNT - 1;
Ã,  while (cur >= 0)
Ã,  {
Ã,  Ã,  int inv = INV_COUNT - 1;
Ã,  Ã,  while (inv >= 0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  SetInvCursor(cur, inv, "");
Ã,  Ã,  Ã,  inv = inv - 1;
Ã,  Ã,  }
Ã,  Ã,  cur = cur - 1;
Ã,  }Ã,  


all looks good.

I must have copied and pasted this for my InvInv Loop and missed a few changes and got...


Code: ags



Ã,  int invcur = INV_COUNT - 1;
Ã,  while (invcur >= 0)
Ã,  {
Ã,  Ã,  int invclick = INV_COUNT - 1;
Ã,  Ã,  while (invclick >= 0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  SetInvCursor(invcur, invclick, "");Ã,  Ã, // this is now SetInvInv(invcur, invclick, "")
Ã,  Ã,  Ã,  invclick = invclick - 1;
Ã,  Ã,  }
Ã,  Ã,  invcur = invcur - 1;
Ã,  }Ã,  
Ã,  


I finally figured this out, because I put Displays in the SetInvCursor function and was initially getting good #'s, but then I was getting #'s that were TOTALLY wrong.

That's when I discovered my initialization was messed up.Ã,  Once I changed it to the correct function, everything has worked perfectly since.

Why didn't the code blow up when I tried to init an index on my array that didn't exist?
I don't have any safety code around the Set function, so it was trying to access element 600+ when there were only 338..

Anyway, I'm for now good, and am able to continue.




website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

Pumaman

2.62 has no array bounds protection, so you can do this sort of thing and potentially corrupt memory elsewhere.

2.7 introduces array bounds checking, so that you get an error message in this scenario.

Etcher Squared Games

Ah, fair enough.  Since I'm going to finish this project off in 2.62 I'll go ahead and put more secure self-checks in there to make sure something like this doesn't happen again.

Thanks for the help CJ.
website: http://www.etcher2games.com/
email: etcher2games@yahoo.com
forum: http://www.etcher2games.com/forums

Anyone want to make my website for free?

SMF spam blocked by CleanTalk