Illegal Exception when setting DrawingColor?

Started by Nine Toes, Sun 10/05/2009 21:53:08

Previous topic - Next topic

Nine Toes

I get this message when I test out my game:

Quote
---------------------------
Illegal exception
---------------------------
An exception 0xC0000005 occurred in ACWIN.EXE at EIP = 0x00403946 ; program pointer is -42, ACI version 3.12.1074, gtags (0,2)

AGS cannot continue, this exception was fatal. Please note down the numbers above, remember what you were doing at the time and post the details on the AGS Technical Forum.

in "GlobalScript.asc", line 19
from "GlobalScript.asc", line 34

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)

Here is my script:

Code: ags

// main global script file
#define MAP_TILES_HIGH 9
#define MAP_TILES_WIDE 9
#define MAP_TILES_TOTAL 81
#define TILE_HEIGHT 32
#define TILE_WIDTH 32

int tile[MAP_TILES_TOTAL];

DrawingSurface *surface;

function SetTile (int x,  int y,  int value) {
  if (x<0 || x>MAP_TILES_WIDE || y<0 || y>MAP_TILES_HIGH) {
    Display ("Error: Out of bounds");
    QuitGame (0);
  }
  tile[y*MAP_TILES_WIDE+x] = value;
  surface = Room.GetDrawingSurfaceForBackground();
  surface.DrawingColor = Game.GetColorFromRGB(255, 0, 0);  // <---Illegal exception, line 19
  surface.DrawRectangle(x, y, x+TILE_HEIGHT, y+TILE_WIDTH);
  surface.Release();
}

function GetTile (int x,  int y) {
  if (x<0 || x>MAP_TILES_WIDE || y<0 || y>MAP_TILES_HIGH) {
    Display ("Error: Out of bounds");
    QuitGame(0);
  }
  return tile[y*MAP_TILES_WIDE+x];
}

#sectionstart game_start  // DO NOT EDIT OR REMOVE THIS LINE
function game_start() { // called when the game starts, before the first room is loaded
  SetTile(0, 0, 0);  // <--- Illegal exception, line 34
  SetTile(32, 0, 0);
  SetTile(64, 0, 0);
  SetTile(96, 0, 0);
  SetTile(128, 0, 0);
  SetTile(160, 0, 0);
  SetTile(192, 0, 0);
  SetTile(224, 0, 0);
  SetTile(256, 0, 0);
  SetTile(0, 32, 0);
  SetTile(32, 32, 0);
  SetTile(64, 32, 0);
  SetTile(96, 32, 0);
  SetTile(128, 32, 0);
  SetTile(160, 32, 0);
  SetTile(192, 32, 0);
  SetTile(224, 32, 0);
  SetTile(256, 32, 0);
  SetTile(0, 64, 0);
  SetTile(32, 64, 0);
  SetTile(64, 64, 0);
  SetTile(96, 64, 0);
  SetTile(128, 64, 0);
  SetTile(160, 64, 0);
  SetTile(192, 64, 0);
  SetTile(224, 64, 0);
  SetTile(256, 64, 0);
  }
#sectionend game_start  // DO NOT EDIT OR REMOVE THIS LINE


I've got no idea why I'm getting this message, I was literally doing everything by the book.

EDIT:  Sorry, I forgot to mention what I was doing when this happened - Um, well, this script is supposed to be for a tile-based game.  I got the original script from Scorpiorus, in this thread.  I really don't know what I'm doing, but I'm trying to learn as I go.

Basically what I was trying to do is to see if I could get these tiles to represent themselves on screen by using the DrawRectangle command.
Watch, I just killed this topic...

Pumaman

You can't use Room.GetDrawingSurfaceForBackground() in game_start, because no room is loaded so there is no background to draw onto.


Khris

Hmm:
Code: ags
function game_start() { // called when the game starts, before the first room is loaded


Considering the above comment, I'm surprised the error doesn't occur sooner, at this line:

Code: ags
 surface = Room.GetDrawingSurfaceForBackground();


Try calling SetTile() in room_Load().

Nine Toes

Quote from: Pumaman on Sun 10/05/2009 22:46:07
You can't use Room.GetDrawingSurfaceForBackground() in game_start, because no room is loaded so there is no background to draw onto.

*laughs*  Yeah, I suppose.  Wow, I'm a dummy. :P

I will try KhrisMUC's solution.
Watch, I just killed this topic...

SMF spam blocked by CleanTalk