Jump to content
  • Advertisement
Sign in to follow this  
EverIce

Deleting template class in dll makes runtime error

This topic is 5405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a template class that worked well before exporting to dll. But after that it makes runtime error when calling destructor. It looks like :
template <class T>
class X
{
   *T mData;
   ~X()
  {
    if (mData)
    delete mData;
  }
};

Can you help me finding how could this be happened ?

Share this post


Link to post
Share on other sites
Advertisement
mData is probably allocated in the exe. You can't allocate memory in the exe and deallocate it in the DLL (or vice-versa), because with the static linked CRT, the DLL and exe get different heaps. Free the memory from the exe, allocate it in the DLL, or use the DLL version of the CRT - but you'll have to make sure both apps link with the exact same version, i.e. You can't have one linked with the single threaded debug CRT and one with the multithreaded debug, and you can't mix debug/release versions and compiler versions.

Share this post


Link to post
Share on other sites
Uh, that was fast, thanks.

But i don't get fully your suggestion.

"use the DLL version of the CRT " - it means that my app and my dll runtime library must be single-threaded debug ?

Otherwise i have to change the code ?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!