Sign in to follow this  
Bruno

Works in VC6++, fails in VC2003

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.





Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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();
}



Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Oops, Here's the constructor :


CalCoreModel::CalCoreModel(const std::string& name)
: m_strName(name)
, m_pCoreSkeleton(0)
, m_userData(0)
{
}


Which calls yet another one :


CalCoreSkeleton::CalCoreSkeleton() : m_referenceCount(0)
{
}


How do the code tags work ? the syntax ?

Share this post


Link to post
Share on other sites
The source tags work like so:

[__source__]
// Your C++ code
// ...
// ...

[__/source__]

Just omit the underscores.



As for your CalCoreModel constructor, I can't see anything wrong with it ... except you say it calls the constructor of class CalCoreSkeleton ... I'm assuming by making an instance of that class ... but I don't see where. You seem to be using Hungarian notation so I take it your m_pCoreSkeleton member is a pointer to a CalCoreSkeleton instance, and you're only setting that to null in your example?

Share this post


Link to post
Share on other sites
Ok, got it working, lol

The problem is that, i had imported the project from VC6 , and the working directory was being aimed at the folder where the vc6 project was, so the vc2003 project was actually using the library dll compiled for vc6 instead of the library dll compiled for the vc2003 version., so, my bad :)

thanks anyways guys

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