Fatal exception using player.ChangeRoom (SOLVED)

Started by The Bedminster Incident, Sun 22/01/2006 00:45:58

Previous topic - Next topic

The Bedminster Incident

I got a 0xC0000005 in ACWIN.EXE at EIP = 0x00447F39 (program pointer: -42, ACI v2.71.894, gtags(188,24)) when trying to test run my game.

Everything worked perfectly well until I had the following idea:
The title screen shows up after the introduction (kind of like MI). When first running the game, an "intro flag" is created in a seperate file (int, value 1). The purpose of this is that the intro sequence is shown only when running the game for the 1st time, after that, the title screen would show up directly. (Of course, there's a button for viewing the intro again.)

Now, here's what I did:
This code excerpt is from game_start():

    File *iflag = File.Open("intro.flg", eFileRead);
    if(iflag!=null) {
      if(iflag.ReadInt()) player.ChangeRoom(1, 0, 0);
      else mouse.Visible = false;
      iflag.Close();
    } else mouse.Visible = false;

As the default starting room of course is room 0 (the intro room), if there's an error or the var isn't set or something, I just need to turn the mouse visibility off.
Then, in the room script for room 0 I put the following directly after the EndCutscene() command:

  File *iflag = File.Open("intro.flg", eFileWrite);
  if(iflag!=null) {
    iflag.WriteInt(1);
    iflag.Close();
  }

I figured this should work fine, although it might not be the most efficient way of scripting this. It works fine when running the game for the first time, but when the flag is set to 1 and I re-run the game, the exeption posted above occurs.

Now, I'm not quite shure if this is really a bug or just some big scripting mistake by silly me. In both cases, I don't know how to fix this, so I'd be happy if anybody here could help me.

Thanks in advance.

- Blodvarg
A la fin, il y aura seulement de la beauté.

Gilbert

Try moving the game_start checking codes to one of the "Player enters room XXXXXXX (XXXX)" events instead.
The problem is, when game_start() was being executed, the game environment was not fully initialized (e.g., no room, sprite, etc. was loaded yet), so you can do only basic initializations like changing a variable (maybe loading a file is okay), but no room/object/etc. -specific stuff can be done yet, I think your crash was caused by the player.ChangeRoom() function, since not even the first room was loaded and you tell the player to change the room already.

I think maybe the script compiler should be better-tuned to detect the existense of such functions in the game_start() function so to give a warning first, other than crashing when you run the game.

The Bedminster Incident

I somehow hoped that ChangeRoom() would also be able to set the player's starting room. So, yes, that was exactly what I did wrong.
Thanks.

- Blodvarg
A la fin, il y aura seulement de la beauté.

strazer

Chris, shouldn't AGS handle this more gracefully?

monkey0506


Pumaman

Yes, it should. I'll put in a specific check in ChangeRoom to handle this.

The problem is that there are various things that can break if called in game_start, and since most of the AGS code assumes that a room is currently loaded, it would be quite a large task to deal with every possible eventuality.

However fixing the commonly used functions such as ChangeRoom to detect this situation is certainly worth doing.

SMF spam blocked by CleanTalk