Need help understanding error message. (SOLVED)

Started by Ali, Sun 15/04/2007 13:49:58

Previous topic - Next topic

Ali

A couple of people have reported this error message in Nelly Cootalot:

Quote
An internal error has occured [sic]. Please note down the following information.
If the problem persists, contact Chris Jones.
(ACI version 2.72.920)
Error: run_text_script1: error -6 running function 'LoadList_SelectedIndex':
Error: Array index out of bounds (index: 23, bounds: 0..19)
in Global script (line 1494)

I can't recreate the error, but I'm not actually sure what the error report means.

Below is the script in question. It's called when the selection is changed on a listbox called LoadList. The idea is to show a screenshot from the currently selected game on the button called LoadScreen.

Code: ags

function LoadList_SelectedIndex(GUIControl *control) {
  
if (buttonSprite != null) {
buttonSprite.Delete();
}
listselected = LoadList.SelectedIndex;
buttonSprite = DynamicSprite.CreateFromSaveGame(savegameindex[listselected],82,61); //this is line 1494
if (buttonSprite != null) {
LoadScreen.NormalGraphic = buttonSprite.Graphic;
}
}


As I say, this worked fine when I tried it, I wondered if you could spot a potential problem.

Thanks,

Ali.

Gilbert

I'm not sure if this can happen (as I never played the game), but when there's no item selected in a listbox, SelectedIndex will return -1, in this case savegameindex[listselected] would be just savegameindex[-1], according to your codes, which obviously will cause an Array out-of-bound error.

You need to check this before calling the array (unless you DID already check whether there're something selected in the listbox somewhere else):
Code: ags

function LoadList_SelectedIndex(GUIControl *control) {
  if (buttonSprite != null) {
    buttonSprite.Delete();
  }
  listselected = LoadList.SelectedIndex;
  if (listselected!=-1) {
    buttonSprite = DynamicSprite.CreateFromSaveGame(savegameindex[listselected],82,61); //this is line 1494
    if (buttonSprite != null) LoadScreen.NormalGraphic = buttonSprite.Graphic;
  }
}

GarageGothic

#2
The code is very close to my own savegame menu, I compared them and it looks fine to me.
The only reason I could think of is that you've forgotten to FillSaveGameList() again somewhere after a savegame has been deleted. That would mean there could be more items in the LoadList than there are savegame indexes.


Edit: I managed to recreate it:

QuoteError: run_text_script1: error -6 running function 'LoadList_SelectedIndex':
Error: Array index out of bounds (index: 20, bounds: 0..19)
in Global script (line 1494)

I saved a LOT of new games, then tried to restore one of the oldest. It seems that games beyond index 19 can't be restored. And I think I found the reason. You're still using savegameindex[], but more than 20 savegames. This is from the changefile for AGS 2.72:

QuoteObsoleted savegameindex[] array, and added ListBox.SaveGameSlots[]
   array instead. Additionally, raised the max save games from 20 to 50.

I take it from this that savegameindex may still have the old limit. Try rewriting the code using ListBox.SaveGameSlots instead and see if that works.

Edit 2: Yep, similar problem in my code which also uses savegameindex[] yet allows 50 savegames. I'll fix my own code now and let you know if it helped.

Edit 3: Yeah, it solved all my problems. Changing savegameindex[listselected] to LoadList.SaveGameSlots[listselected] should do the trick.

Ali

Thanks guys. Gilbot, that was my first thought too. However, because it's impossible to deselect the listbox in my game, I didn't think it would be that.

GarageGothic, many thanks for pointing that out. I'm glad my incompetence helped you tighten up your script too!

SMF spam blocked by CleanTalk