Skip to main content
gamedev.net
🔒 Locked

[SOLVED]Rendering artifacts in debug mode (c++)

Started by PSS 1 reply 1k views
Original Post
PSS
PSS
While in the default Debug Solution Configuration, my meshes render as arbitrary artifacts. This only occurs when my mesh wrapper is initialized with 'new'.

... 

CMeshWrapper*	m_pEnt;	
CMeshWrapper	m_Ent;

...
OnCreate( ... )
{
   m_pEnt = new CMeshWrapper();  //Constructor sets internal mesh to NULL
   m_pEnt->SetMesh( "mesh.x" );  //Creates the mesh

   m_Ent.SetMesh( "mesh.x" );    //Creates the mesh
}
OnRender( ... )
{
...
   m_pEnt->Render( ... );
   m_Ent.Render( ... );
...
}


Note: I've tried every order possible between the two mesh wrappers, and the mesh is ALWAYS created the same way and seems valid when rendering (how can I check this for sure?). After looking for a while, I haven't been able to find a reason for this. What differences do heap allocations have in debug mode vs release mode? Or am I doing something wrong? [Edited by - PSS on April 23, 2009 11:51:59 AM]
Kippesoep
Kippesoep
Memory allocations in debug mode will have a few bytes of padding before and after the memory allocated for your program. This allows the runtime library to do consistency checks on the heap and warn you when you've written outside the buffer (you'd get an assertion failure).

This is most likely not the cause of the problem, though. It's more likely that you have uninitialised member variables in your class. In release mode, uninitialised variables get whatever value happens to be in memory at that time (which often ends up at 0, thus masking the actual problem and making it even harder to trace). In debug mode, everything will be initialised to a special value, usually 0xCCCCCCCC.

When running your program through a debugger, this will allow you to spot uninitialised variables easily in the memory/object inspector.

Check out your constructor to make sure it initialises every member variable.
Kippesoep
PSS
PSS
Thank you very much for the quick response, and pointing me in the right direction!

After closely reviewing all of the object constructors, I noticed that one of the wrapper's derived class was not initializing anything. Cleaning up that class fixed the issue.

Thanks again!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.