Debug vs Release (vc6)

Started by
11 comments, last by Muncher 19 years, 9 months ago
Um, ok My project runs perfectly in debug mode... but not in release mode. I isolated the problem to a section of code where i create a temporary block of memory with 'new' and draw it into a display list, then 'delete' it. I can fix the problem by allocating the array with a max_size at compile time... I just have to ask does release mode handle allocation/deallocation of memory differently to debug mode?? Muncher
Advertisement
Interesting... what kind of error do you get? By any chance, is it an "assert" error?
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
yep, that dialog box comes up with 'debug' 'break' 'continue' for the assert error :(
Ah, I had this problem before! Let me see... it was so long ago, but I remember I struggled with it for a month before I figured it out. I just can't seem to remember what it was.

I think it had something to do with not referring to pointers in the proper way. It would work in the more protected Debug mode, but would fail in release testing. Post up the bit of code you narrowed it down to, perhaps we can figure it out.

EDIT: I just found this, and it sounds familiar...

The debug allocator also checks the storage at the start and end of the block it allocated to see if it has been damaged in any way. The typical problem is that you have allocated a block of n values as an array and then accessed elements 0 through n, instead of 0 through n-1, thus overwriting the area at the end of the array. This condition will cause an assertion failure most of the time. But not all of the time. And this leads to a potential for failure.

So check to see that you're not using an array out of its bounds.
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
do you have the most recent vc6 service pack? i know i had some release problems, so i dl'd a service pack and they got fixed.
Oh yeah! Good idea... you know what, now that I'm thinking about it that might've been the problem! He said that, and it reminded me that I did that to a problem and it went away... maybe that's the case here. Yeah, definately update your copy of VStudio 6 and see if it helps.
-Vendal Thornheart=) Programming for a better tomorrow... well,for a better simulated tomorrow. ;)
try initializing all your Pointers in non-extremly-time-critical sections with null or a valid value :)
and you should check before using them....

another possibility is, that you are writing out of the bounds of a memory chunk
I got the latest vc6 service pack. It didn't make a difference
:(
I'll post the code below, it is per polygon lightmaps into a larger lightmap.
b_rgb is a unsigned char red,green,blue structure.

// Pack the lightmaps into one lightmap for the entire node!
// Count the number of required lightmaps
int numLightMaps = solidIndex;
int mapSize = 0;


if (numLightMaps+1 < ((128*128) / LIGHTMAP_SIZE))
mapSize = 128;
else if (numLightMaps+1 < ((256*256) / LIGHTMAP_SIZE))
mapSize = 256;
else if (numLightMaps+1 < ((512*512) / LIGHTMAP_SIZE))
mapSize = 512;
else if (numLightMaps+1 < ((1024*1024) / LIGHTMAP_SIZE))
mapSize = 1024;
// Variables to help crunch the lightmap
int lightMapWidth = (int)sqrt(LIGHTMAP_SIZE);

// Allocate space for the lightmap
b_rgb *map = new b_rgb[mapSize*mapSize];

int xIndex = 0;
int yIndex = mapSize-lightMapWidth;
int row = 0;
int col = 0;

memset(map,0,sizeof(map));


for (int lMap = 0; lMap < numLightMaps; lMap++)
{
for (int yi = 0; yi < lightMapWidth; yi++)
{
for (int xi = 0; xi < lightMapWidth; xi++)
{
int mapX = xIndex+xi;
int mapY = yIndex+yi;
int mapIndex = mapX + (mapY * mapSize);
map[mapIndex] = solidPolys[lMap].lightmap.texels[xi+(yi*lightMapWidth)];
}
}

xIndex += lightMapWidth;
col++;
if (xIndex > mapSize-lightMapWidth)
{
xIndex = 0;
col = 0;
row++;
yIndex -= lightMapWidth;
}
}
// Pack the lightmaps into one lightmap for the entire node!// Count the number of required lightmapsint numLightMaps = solidIndex;int mapSize = 0;if (numLightMaps+1  <  ((128*128) / LIGHTMAP_SIZE))     mapSize = 128;else if (numLightMaps+1  < ((256*256) / LIGHTMAP_SIZE))      mapSize = 256;else if (numLightMaps+1  < ((512*512) / LIGHTMAP_SIZE))      mapSize = 512;else if (numLightMaps+1  < ((1024*1024) / LIGHTMAP_SIZE))     mapSize = 1024;// Variables to help crunch the lightmapint lightMapWidth = (int)sqrt(LIGHTMAP_SIZE);// Allocate space for the lightmapb_rgb *map        = new b_rgb[mapSize*mapSize];	int xIndex = 0;int yIndex = mapSize-lightMapWidth;int row = 0;int col = 0;memset(map,0,sizeof(map));for (int lMap = 0; lMap < numLightMaps; lMap++){   for (int yi = 0; yi < lightMapWidth; yi++)  {	for (int xi = 0; xi < lightMapWidth; xi++)	{	int mapX = xIndex+xi;	int mapY = yIndex+yi;	int mapIndex = mapX + (mapY * mapSize);	map[mapIndex] = solidPolys[lMap].lightmap.texels[xi+(yi*lightMapWidth)];	}  }  xIndex += lightMapWidth;  col++;  if (xIndex > mapSize-lightMapWidth)  {    xIndex = 0;    col = 0;    row++;    yIndex -= lightMapWidth;  }}

You are making a few mistakes. First of all, your memset is broken, and the correct way of doing it would be:

b_rgb *map        = new b_rgb[mapSize*mapSize];memset(map, 0, sizeof(map) * (mapSize * mapSize));


That will erase the entire memory of the pointer.
Secondly, are you surre LightMapWidth and LightMapHeight and NumLightMaps aren't exceeding bounds? If mapSize is 5, new will return 25 times. But, the MapX and MapY are calculated a la xIndex+xi and yIndex+yi. If those are becoming a number larger than 5, you will exceed the bounds of the memory at one point.

How to fix this:
Set a breakpoint in the debugger at the line:
int mapIndex = mapX + (mapY * mapSize);

And then step through the loop with F5. Everytime you reach the line, eval the answer. If mapIndex exceeds the 25(Which it will, since you are getting ASSERT errors), you are doing something wrong.

Consider rewriting the code, it looks messy, and I have no idea what you are doing.

Toolmaker

This topic is closed to new replies.

Advertisement