Works in VC6++, fails in VC2003
Hi.,
Well, i'm porting my code from VC6 to VC2003, and i'm having some problems with it.
The code compiles and links fine, but crashes in places, where in vc6 was ok.,
This piece here :
class Model
{
public:
int m_state;
bool Initialized;
CalCoreModel *m_calCoreModel;
CalHardwareModel *m_calHardwareModel;
};
Model *pModel;
pModel = new Model();
pModel->onInit(Mesh_to_Open);
Inside the onInit function, i have this line :
m_calCoreModel = new CalCoreModel();
and it crashes, invalid memory blablabla, while in VC+ works fine, no leaks, nothing.
Any clue on what is going wrong here ?
thanks
You'll need to post more code, including the exact code for the constructors in question, and the code that invokes them. Also, post the exact error message.
VC6 is (correctly) regarded as a terrible compiler, so its good you're porting to something more standards-compliant.
VC6 is (correctly) regarded as a terrible compiler, so its good you're porting to something more standards-compliant.
Here it goes :
Model *pModel;
typedef struct myMesh
{
CalModel *anim;
};
myMesh myBot;
I call the function like this :
pModel = new Model();
myBot.anim = pModel->onInit(Mesh_to_Open, myBot.anim );
The constructor :
class Model
{
public:
bool Initialized;
CalCoreModel *m_calCoreModel;
CalHardwareModel *m_calHardwareModel;
Model();
~Model();
CalModel* onInit(const std::string& strFilename, CalModel *m_calCoreModel);
}
Model::Model()
{
Initialized = 1;
}
CalModel* Model::onInit(const std::string& strFilename, CalModel *m_calModel)
{
m_calCoreModel = new CalCoreModel("");
And crashes right here, with this message :
Unhandled exception at 0x7609d9ca in test.exe: 0xC0000005: Access violation reading location 0x6d6d7563.
Model *pModel;
typedef struct myMesh
{
CalModel *anim;
};
myMesh myBot;
I call the function like this :
pModel = new Model();
myBot.anim = pModel->onInit(Mesh_to_Open, myBot.anim );
The constructor :
class Model
{
public:
bool Initialized;
CalCoreModel *m_calCoreModel;
CalHardwareModel *m_calHardwareModel;
Model();
~Model();
CalModel* onInit(const std::string& strFilename, CalModel *m_calCoreModel);
}
Model::Model()
{
Initialized = 1;
}
CalModel* Model::onInit(const std::string& strFilename, CalModel *m_calModel)
{
m_calCoreModel = new CalCoreModel("");
And crashes right here, with this message :
Unhandled exception at 0x7609d9ca in test.exe: 0xC0000005: Access violation reading location 0x6d6d7563.
Chances are that you have a DLL linkage problem. VC++ 2003 uses a different C/C++ runtime library (MSVCRT71.DLL and the debugging analog) whereas VC++ 6.0 uses the version 6 library (MSVCRT.DLL and the debugging version).
If you're linking against another pre-compiled library (say, "Cal") then you should attempt to get libraries compiled for the version of the Microsoft compiler you're using, to minimize the possibility of runtime mis-match errors.
If you're linking against another pre-compiled library (say, "Cal") then you should attempt to get libraries compiled for the version of the Microsoft compiler you're using, to minimize the possibility of runtime mis-match errors.
I was going too, eheh, here it goes :
CalCoreModel::~CalCoreModel()
{
// destroy all core materials
std::vector<CalCoreMaterial *>::iterator iteratorCoreMaterial;
for(iteratorCoreMaterial = m_vectorCoreMaterial.begin(); iteratorCoreMaterial != m_vectorCoreMaterial.end(); ++iteratorCoreMaterial)
{
if(*iteratorCoreMaterial)
{
if((*iteratorCoreMaterial)->decRef())
{
delete (*iteratorCoreMaterial);
}
}
}
m_vectorCoreMaterial.clear();
// destroy all core meshes
std::vector<CalCoreMesh *>::iterator iteratorCoreMesh;
for(iteratorCoreMesh = m_vectorCoreMesh.begin(); iteratorCoreMesh != m_vectorCoreMesh.end(); ++iteratorCoreMesh)
{
if(*iteratorCoreMesh)
{
if((*iteratorCoreMesh)->decRef())
{
delete (*iteratorCoreMesh);
}
}
}
m_vectorCoreMesh.clear();
// destroy all core animations
std::vector<CalCoreAnimation *>::iterator iteratorCoreAnimation;
for(iteratorCoreAnimation = m_vectorCoreAnimation.begin(); iteratorCoreAnimation != m_vectorCoreAnimation.end(); ++iteratorCoreAnimation)
{
if(*iteratorCoreAnimation)
{
if((*iteratorCoreAnimation)->decRef())
{
delete (*iteratorCoreAnimation);
}
}
}
m_vectorCoreAnimation.clear();
// destroy all core morph animations
std::vector<CalCoreMorphAnimation *>::iterator iteratorCoreMorphAnimation;
for(iteratorCoreMorphAnimation = m_vectorCoreMorphAnimation.begin(); iteratorCoreMorphAnimation !=
m_vectorCoreMorphAnimation.end(); ++iteratorCoreMorphAnimation)
{
delete (*iteratorCoreMorphAnimation);
}
m_vectorCoreMorphAnimation.clear();
if(m_pCoreSkeleton != 0)
{
if(m_pCoreSkeleton->decRef())
{
delete m_pCoreSkeleton;
}
m_pCoreSkeleton = 0;
}
m_strName.erase();
}
CalCoreModel::~CalCoreModel()
{
// destroy all core materials
std::vector<CalCoreMaterial *>::iterator iteratorCoreMaterial;
for(iteratorCoreMaterial = m_vectorCoreMaterial.begin(); iteratorCoreMaterial != m_vectorCoreMaterial.end(); ++iteratorCoreMaterial)
{
if(*iteratorCoreMaterial)
{
if((*iteratorCoreMaterial)->decRef())
{
delete (*iteratorCoreMaterial);
}
}
}
m_vectorCoreMaterial.clear();
// destroy all core meshes
std::vector<CalCoreMesh *>::iterator iteratorCoreMesh;
for(iteratorCoreMesh = m_vectorCoreMesh.begin(); iteratorCoreMesh != m_vectorCoreMesh.end(); ++iteratorCoreMesh)
{
if(*iteratorCoreMesh)
{
if((*iteratorCoreMesh)->decRef())
{
delete (*iteratorCoreMesh);
}
}
}
m_vectorCoreMesh.clear();
// destroy all core animations
std::vector<CalCoreAnimation *>::iterator iteratorCoreAnimation;
for(iteratorCoreAnimation = m_vectorCoreAnimation.begin(); iteratorCoreAnimation != m_vectorCoreAnimation.end(); ++iteratorCoreAnimation)
{
if(*iteratorCoreAnimation)
{
if((*iteratorCoreAnimation)->decRef())
{
delete (*iteratorCoreAnimation);
}
}
}
m_vectorCoreAnimation.clear();
// destroy all core morph animations
std::vector<CalCoreMorphAnimation *>::iterator iteratorCoreMorphAnimation;
for(iteratorCoreMorphAnimation = m_vectorCoreMorphAnimation.begin(); iteratorCoreMorphAnimation !=
m_vectorCoreMorphAnimation.end(); ++iteratorCoreMorphAnimation)
{
delete (*iteratorCoreMorphAnimation);
}
m_vectorCoreMorphAnimation.clear();
if(m_pCoreSkeleton != 0)
{
if(m_pCoreSkeleton->decRef())
{
delete m_pCoreSkeleton;
}
m_pCoreSkeleton = 0;
}
m_strName.erase();
}
Quote:Original post by hplus0603
Chances are that you have a DLL linkage problem. VC++ 2003 uses a different C/C++ runtime library (MSVCRT71.DLL and the debugging analog) whereas VC++ 6.0 uses the version 6 library (MSVCRT.DLL and the debugging version).
If you're linking against another pre-compiled library (say, "Cal") then you should attempt to get libraries compiled for the version of the Microsoft compiler you're using, to minimize the possibility of runtime mis-match errors.
Yeah, i tought about that, i already recompiled the library with VC++ 2003 with no problems.
The CONstructor, mate, not the DEstructor. Also, please put your code inside source tags to make it more readable for us. ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement