I have a memory corruption problem in one of my programs. I tell the joke to see what my problem (or google has been able to help me)
I have a DLL THROUGH class function returns a variable of type b2World and that I can create new physical bodies (reference memory). When my program (which uses the DLL) tries to create any physical body falls, in fact to do a lot of debugging I realized that the data change when more memory is requested. However when I do exactly the same code to create the body within the same DLL, this does not fall
In the dll I have put him dllimport and dllexport all, except that linking Box2D in both statically and in program. Both dll as the dll and the program I have the code.
I’m using Visual Studio (but I have the same problems using codeblocks-mingw another compiler).
I hope you can help me because I have searched Google and have not caught nothing (probably incorrect search words).
Program:
bool Gameloop::load(){
m_world = new World();
b2World &world = m_world->getWorld();
b2BodyDef def;
def.position.Set(100,100);
def.type = b2_staticBody;
b2Body *body = world.CreateBody(&def);
b2PolygonShape box;
box.SetAsBox(5,5);
b2FixtureDef fixtureDef;
fixtureDef.shape = &box;
body->CreateFixture(&fixtureDef);
return true;
}
(problem in CreateBody and CreateFixture)
Probably your dll was compiled with another version of runtime library than you currently use. Normally you cannot export classes from dll you should use interfaces instead – read this http://www.codeproject.com/KB/cpp/howto_export_cpp_classes.aspx. The solution of this problem may be to recompile your dll with runtime version you currently use. The better solution in this case should be the statically linking this library to your project.