DrawSurface crash

Started by TheJBurger, Fri 26/09/2008 03:22:08

Previous topic - Next topic

TheJBurger

I have a DrawImage code running in the RepEx, which repeats over and over to achieve a type of rain effect. It works as it should, except in some instances, loading a game during the rain code causes a crash which I can't seem to fix.  The entire crash message is as follows:
Code: ags
---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x00436A9D ; program pointer is +1004, ACI version 3.02.1025, gtags (30,0)

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.

in "room3.asc", line 549


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

An error file CrashInfo.dmp has been created. You may be asked to upload this file when reporting this problem on the AGS Forums. (code 0)
---------------------------
OK   
---------------------------



...And Here is the code (line 549 is near the bottom):
Code: ags
  // Rain Code
  if (gCommunicator.Visible == false && gVerbCoin.Visible == false) {
    raintimer++;
  if (raintimer == 1) {
    surface = Room.GetDrawingSurfaceForBackground();
    backup = surface.CreateCopy();
    doover=0;
    doover2=0;
    while (doover < 100) { // 100 raindrops
    int y=(165+Random(35)); // 165-200 drawing area.
    int x=Random(320); // whole screen.
    if (Region.GetAtRoomXY(x, y) == region[1] || Region.GetAtRoomXY(x, y) == region[7] || Region.GetAtRoomXY(x, y) == region[10]) {
    surface.DrawImage(x, y, 303, (60+Random(40)));
    doover++;
      }
     }
   while (doover2 < 50) { // 50 raindrops
    int y=(107+Random(10)); // 165-200 drawing area.
    int x=(90+Random(230)); // whole screen.
    if (Region.GetAtRoomXY(x, y) == region[9]) {
    surface.DrawImage(x, y, 303, (60+Random(40)));
    doover2++;
      }
     }
   
    }
  if (raintimer == 5) {
    surface.DrawSurface(backup); // THIS LINE CRASHES --- Line 549 ----------- CRASHY CRASH CRASH
        surface.Release();
    backup.Release();

    raintimer=0;
    }
  }
  // End Rain Code

When I load certain saved games, the game crashes on the 'surface.DrawSurface(backup);' line. I assume it's because there's no backup to draw for some reason, but I can't figure out how to fix it.

Gilbert

I did not read the code thoroughly, but I suspect that there may be a limitation (glitch?) the the engine does not save the value of a pointer and/or the (drawing surface) content it points to in a save game.

I'll say this post is more suitable in the Technical forum.

Khris

Did you declare the DrawingSurface variables outside the function?

TheJBurger

Yes, I did it at the top of the room script.

Khris

Try switching to global variables, maybe it'll work then.

Pumaman

This should work correctly, so the crash looks like it's probably a bug in AGS.

Would it be possible to upload the game along with a save game file that causes it to crash?

Alternatively, could you upload the CrashDump file?

TheJBurger

Quote from: Pumaman on Fri 26/09/2008 20:55:11
This should work correctly, so the crash looks like it's probably a bug in AGS.

Would it be possible to upload the game along with a save game file that causes it to crash?

Alternatively, could you upload the CrashDump file?

I've PMed you the file.

Pumaman

Thanks. I've investigated this and it is indeed a bug in AGS, which I will fix for the next version.

On a related topic, be careful when using backup DrawingSurfaces in rooms; because when the player leaves that room, you'll potentially still have the "backup" surface stored in memory for the rest of the game. I'd recommend making sure you have some code in the Player Leaves Room event to reset the raintimer and Release the backup surface if it's in use, to prevent this happening.

TheJBurger

Quote from: Pumaman on Sat 27/09/2008 15:37:03
I'd recommend making sure you have some code in the Player Leaves Room event to reset the raintimer and Release the backup surface if it's in use, to prevent this happening.

Okay, I reset the raintimer and released both 'backup' and 'surface' drawing surfaces when the player leaves each different room. I tried to recreate the same situation but it didn't crash this time. So for now, it seems to be fixed unless I keep trying different save game/room combinations. Thanks for your help!

SMF spam blocked by CleanTalk