Sign in to follow this  
Drats

Access violation writing location [SOLVED]

Recommended Posts

Hi I am getting the usual Access violation runtime errors and I can't figure out what the problem is. The piece of code is
    m_nTextureCount    = 0;
    m_nMaterialCount   = 0;
    m_nAttribCount     = 0;
    m_nLightCount      = 0;
    m_nMeshCount       = 0;
    m_pMesh            = NULL;


The out put from the debugger is First-chance exception at 0x00419910 in Game Engine.exe: 0xC0000005: Access violation writing location 0x00440fcc. Unhandled exception at 0x00419910 in Game Engine.exe: 0xC0000005: Access violation writing location 0x00440fcc. When I run it through the debugger, texture_count has an extremely high value of 1646295141. Any ideas what the problem might be? Thanks. [Edited by - Drats on August 18, 2008 4:39:22 AM]

Share this post


Link to post
Share on other sites
Sounds like your this pointer is invalid, usually caused by calling a member function on an invalid object. I'd guess that somewhere you call delete on the class, which frees the memory for it, and you then call some member function on that object.

Share this post


Link to post
Share on other sites
I am sure you are right about the 'this' pointer being invalid. The problem is the error occurs right at the beginning in a constructor when I have not called any member function. I don't even get to the point where i can call delete.

Share this post


Link to post
Share on other sites
The error occurs in the CScene manager constructor which is the first to be created. The entire constructor code is:

 
CScene::CScene()
{
// Reset all required values
m_pD3DDevice = NULL;
m_bHardwareTnL = false;
m_strDataPath = NULL;

m_nTextureCount = 0;
m_nMaterialCount = 0;
m_nAttribCount = 0;
m_nLightCount = 0;
m_nMeshCount = 0;
m_pMesh = NULL;
m_nObjectCount = 0;
m_pObject = NULL;

m_nReservedLights = 0;
m_nLightLimit = 0;

ZeroMemory( m_pTextureList, MAX_TEXTURES * sizeof(TEXTURE_ITEM*));
ZeroMemory( m_pMaterialList, MAX_MATERIALS * sizeof(D3DMATERIAL9));
ZeroMemory( m_pLightList, MAX_LIGHTS * sizeof(D3DLIGHT9));
ZeroMemory( m_pAttribCombo, MAX_ATTRIBUTES * sizeof(ATTRIBUTE_ITEM));
ZeroMemory( &m_DefaultMaterial, sizeof(D3DMATERIAL9) );

// Setup blank material
m_DefaultMaterial.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );

}


The exception is thrown up at m_nTextureCount. I used breakpoints at other locations to see if any function was being called before this but none of the breakpoints are hit. Hope this helps.

Share this post


Link to post
Share on other sites
Is the instance of your CScene class global? Can we see where you declare it? 0x00440fcc is somewhere within your application's memory, it's possible that you're editing a read-only variable somehow, and the compiler/OS has put it into a read only segment of memory.

Share this post


Link to post
Share on other sites
Ok guys I managed to get rid of the error. I deleted my debug database file and now it works alright. I suppose there were some old values that were causing the error. Thanks for your help :-) .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this