Thread: Tripple crash program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110

    Bizzare Crashing

    Alright, on startup the program run Init() which has the following relevant code:
    Code:
    for(int y = 0; y < BOARD_HEIGHT; y++)
    {
    	for(int x = 0; x < BOARD_WIDTH; x++)
    	{
    		//Do a switch on the value of the current index
    		// Since we are using a 1D array, we use the equation:
    		// x + y * BOARD_WIDTH  - This allows us to treat it like a 2D array
    		switch( g_BoardArray[ screen[1]+y+TEST ][ x + screen[0] ] )
    		{
    			case W01:
    				g_bmpTiles[x][y] = LoadABitmap("WA01.bmp");
    				break;
    			case W02:
    				g_bmpTiles[x][y] = LoadABitmap("WA02.bmp");
    				break;
    			case F01:
    				g_bmpTiles[x][y] = LoadABitmap("FL01.bmp");
    				break;
    		}
    	}
    }
    This code I run once, I found that out the hardway (I'm using gametutorials tilemaze and modifying it to scroll in-case you wanted to know. In WinMain():
    Code:
    for(int y = 0; y < BOARD_HEIGHT; y++)
    {
    	for(int x = 0; x < BOARD_WIDTH; x++)
    	{
    		// Display each title according to their index.
    		// We take the x and y index and times it by the width and height
    		// in pixels to get the tile position. This makes the nice tile effect we see on screen  
    		DisplayBitmap(&g_Buffer, g_bmpTiles[x][y], TILE_WIDTH * x, TILE_WIDTH * y);  
    	}
    }
    Now this works all fine and dandy IF you want the images to stay the same, (remember how init was run once?) anyway, to be able to scroll I put that loop from Init() into winmain (right before the DisplayBitmap loop, but this caused crashing, so I merged the two loops into one:
    Code:
    for(int y = 0; y < BOARD_HEIGHT; y++)
    {
    	for(int x = 0; x < BOARD_WIDTH; x++)
    	{
    		g_bmpTiles[x][y] = 0;
    		//Do a switch on the value of the current index
    		// Since we are using a 1D array, we use the equation:
    		// x + y * BOARD_WIDTH  - This allows us to treat it like a 2D array
    		
    		switch( g_BoardArray[ screen[1]+y ][ x + screen[0] ] )
    		{
    			case W01:
    				DisplayBitmap(&g_Buffer, LoadABitmap("WA01.bmp"), TILE_WIDTH * x, TILE_WIDTH * y);
    				break;
    			case W02:
    				DisplayBitmap(&g_Buffer, LoadABitmap("WA02.bmp"), TILE_WIDTH * x, TILE_WIDTH * y);
    				break;
    			case F01:
    				DisplayBitmap(&g_Buffer, LoadABitmap("FL01.bmp"), TILE_WIDTH * x, TILE_WIDTH * y);
    				break;
    		} 
    	}
    }
    But this still caused errors, note: all three arrays screen[], g_BoardArray[] and g_bmpTiles[] are global variables.
    Last edited by Dark Nemesis; 01-01-2004 at 12:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char vs int - program crash!!
    By Goldrak in forum C++ Programming
    Replies: 4
    Last Post: 04-07-2006, 08:17 PM
  2. My program causes my compiler to crash
    By carolsue2 in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2006, 04:06 AM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. sprintf() giving crash to program!!
    By maven in forum C Programming
    Replies: 4
    Last Post: 01-01-2006, 12:26 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM