TheInsider
Programmer
Hi,
I'm having some trouble with the code below. I'm actually using Watcom C++ with the 32-bit DOS4GW extender, but I believe my problem is compiler-independant -- I'm new to C++. It's a simple game I'm writing for VGA ModeX/13h, but it's crashing in the commented-out region...
If someone could point out my memory-related issue(s) it would be greatly appreciated. The code compiles without errors or warnings. When executed, DOS goes into VGA mode 13h and then crashes in the commented-out region...I can narrow it down to somewhere around the new or memset keywords. I haven't quite figured out how to debug code in Watcom, so I have to hack my way through this :-(.
Thanks
I'm having some trouble with the code below. I'm actually using Watcom C++ with the 32-bit DOS4GW extender, but I believe my problem is compiler-independant -- I'm new to C++. It's a simple game I'm writing for VGA ModeX/13h, but it's crashing in the commented-out region...
Code:
const SCREEN_WIDTH = 320,
SCREEN_HEIGHT = 200;
const UNIVERSE_WIDTH = SCREEN_WIDTH * 5,
UNIVERSE_HEIGHT = SCREEN_HEIGHT * 5;
const MASK_INDEX = 0;
struct Image
{
unsigned short width,
height;
unsigned char *buffer;
};
Image *g_offscreen,
*g_universe;
void init_environment(void)
{
srand((unsigned)time(0));
set_video_mode(VIDEO_MODE_VGA);
/*
g_offscreen = new Image();
g_offscreen->width = SCREEN_WIDTH;
g_offscreen->height = SCREEN_HEIGHT;
g_offscreen->buffer = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT];
memset(g_offscreen->buffer, MASK_INDEX, SCREEN_WIDTH * SCREEN_HEIGHT);
g_universe = new Image();
g_offscreen->width = UNIVERSE_WIDTH;
g_offscreen->height = UNIVERSE_HEIGHT;
g_offscreen->buffer = new unsigned char[UNIVERSE_WIDTH * UNIVERSE_HEIGHT];
memset(g_universe->buffer, MASK_INDEX, UNIVERSE_WIDTH * UNIVERSE_HEIGHT);
for (unsigned long i = 0; i < (UNIVERSE_WIDTH * UNIVERSE_HEIGHT); i++)
{
if (get_random(0, 9) == 0)
{
g_universe->buffer[i] = (unsigned char)get_random(20, 225);
}
}
*/
}
void cleanup_environment(void)
{
delete[] g_universe->buffer;
delete g_universe;
delete[] g_offscreen->buffer;
delete g_offscreen;
set_video_mode(VIDEO_MODE_TEXT);
}
If someone could point out my memory-related issue(s) it would be greatly appreciated. The code compiles without errors or warnings. When executed, DOS goes into VGA mode 13h and then crashes in the commented-out region...I can narrow it down to somewhere around the new or memset keywords. I haven't quite figured out how to debug code in Watcom, so I have to hack my way through this :-(.
Thanks