![]() |
Heap Corruption
I am trying to put together an obj file loader to use with OpenGL. I can compile the code but when It runs VS tells me that the heap is corrupted.
What do you guys think is causing this problem.:confused: Here is my code: ObjLoader.h :
#include <fstream>:
#include "ObjLoader.h":
#include <iostream> |
Can you post a sample data file so I can test it?
Also note: .obj is a bad choice for an extension - it is already used for the compiler output. |
That would be the standard 3D data format and I thought '.o' was used for object files? At least in the character crunched unix world it is.
|
All sorts of problems in the original code. Some related to the "heap corruption", some not.
1) Never employ "using namespace std;" in a header file. In a header file, you usually need to suspend your laziness, and prefix anything in namespace std with "std::". 2) Your ObjModel implementation relies on a technique known as "lazy initialisation" --- eg pointers set to NULL, and then set to something useful later on. Since you are doing that with multiple pointers, it is an opportunity to forget to set one or more pointers correctly later on. 3) Make the members of ObjModel private. And then provide public member functions that can be used by ObjLoader. Yes, that will mean ObjLoader will not compile (unless you use the member functions). But it gives a means of ensuring that everything that changes an ObjModel is part of ObjModel --- and can therefore enforce any requirements (such as ensuring data is allocated before using it). 4) "delete pointer" (or "delete [] pointer") does not need to be protected with a test of "pointer != NULL", unless you are using a compiler that is very old (probably more than 15 years old). 5) To understand why you are getting heap corruption, let's have a look at some code of yours..... :
void ObjLoader::ReadData(void):
|
| All times are GMT -5. The time now is 1:27 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC