For quite some time now I have had dynamic cubemaps in the game I have been working on. And they’ve been working great. Recently I did some changes to my model loading code, my map generation code etc. And at around that time I noticed that after loading a number of maps (ie. switching between maps) I was getting a crash in NVOGLNT.dll (memory could not be read).
After hunting and pulling out my hair (because naturally the call stack wouldn’t tell me where the problem was). I believe I have found the code that is causing the problem. (See below)
If I comment out these two blocks of code, leaving the normal rendering code in (aka. I disable the use of my cubemaps). My app works fine. Put the code back in and it starts crashing again.
Can someone please have a look and see if there is something really simple that I’m missing in this code (for example, should I unbind the cubemap after I’m finished the code - could that be the problem.
It might be that there’s nothing wrong with the code below, that the problem may be some change in my system (I’ve reinstalled and upgraded my drivers with no luck). Or maybe there’s some really obscure bug that I cannot find - and believe me I’ve looked. But it does seem wierd that this code is the difference between it working and not working.
FYI - I run a geforce 3 Ti200 with detonator 43.45 (I was on 40.72 when this bug first started showing - but I had been running those drivers for months).
if (materials[0].reflectivity != 0.0f && utilGlobal.bMultitexture &&
utilGlobal.bCubeMap && unCubeMapID && !utilGlobal.bDisableCubeMaps &&
utilConsole.variables[GL_DYNAMICCUBEMAPS].bValue)
{
// Setup the reflection cube map.
glClientActiveTextureARB (GL_TEXTURE1_ARB);
glBindTexture (GL_TEXTURE_CUBE_MAP_ARB, unCubeMapID);// If a handle to a pbuffer is supplied then use that…
if (pbuf && utilConsole.variables[GL_RENDERTOTEXTURE].bValue)
{
wglBindTexImageARB ( pbuf, WGL_FRONT_LEFT_ARB );
utilGlobal.HandleGLError( “Binding the pbuffer to a texture object.” );
}glTexGenf (GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGenf (GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGenf (GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);// Adjust the Generated coords.
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glRotatef(utilGlobal.activecamera->rotation.z, 0.0f, 0.0f, 1.0f);
glRotatef(utilGlobal.activecamera->rotation.y, 0.0f, 1.0f, 0.0f);
glRotatef(utilGlobal.activecamera->rotation.x, 1.0f, 0.0f, 0.0f);
glMatrixMode(GL_MODELVIEW);glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INTERPOLATE_EXT);glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE2_RGB_EXT, GL_CONSTANT_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PREVIOUS_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PREVIOUS_EXT);glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA_EXT, GL_SRC_ALPHA);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND2_RGB_EXT, GL_SRC_COLOR);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND2_ALPHA_EXT, GL_SRC_ALPHA);if (utilGlobal.bFullChrome)
{
fCol[0] = fCol[1] = fCol[2] = fCol[3] = 1.0f;
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, fCol);
}
else
{
fCol[0] = fCol[1] = fCol[2] = fCol[3] = materials[0].reflectivity;
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, fCol);
}// Enable the Texture coord generation.
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_T);
}
/*****
*** Rendering code in here…
*****/
// Now we reset all the materials etc.
if (nmaterials > 0 && materials[0].reflectivity != 0.0f &&
utilGlobal.bMultitexture && utilGlobal.bCubeMap && unCubeMapID && !utilGlobal.bDisableCubeMaps &&
utilConsole.variables[GL_DYNAMICCUBEMAPS].bValue)
{
glMatrixMode(GL_TEXTURE); // Select The Modelview Matrix
glPopMatrix();
glMatrixMode(GL_MODELVIEW);// If a handle to a pbuffer is supplied then use that…
if (pbuf && utilConsole.variables[GL_RENDERTOTEXTURE].bValue)
wglReleaseTexImageARB ( pbuf, WGL_FRONT_LEFT_ARB );glClientActiveTextureARB(GL_TEXTURE1_ARB);
fCol[0] = fCol[1] = fCol[2] = fCol[3] = 1.0f;
glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, fCol);glDisable(GL_TEXTURE_CUBE_MAP_ARB);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_T);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
[This message has been edited by rgpc (edited 08-15-2003).]