destroying classes from an external .dll file

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

Recommended Posts

Share on other sites
The problem could be a result of the objects being allocated in the DLL and deleted in the application, but there are many other possibilities. Try stepping through it with a debugger and determining which line causes the crash (for example, are you sure it's the deallocation and not the CShaderBase destructor?).

And as always, with out some code we can only guess.....

Share on other sites
the CShaderBase destructor is empty nothing is done there..

I know it has something to do with that I allocate the memory inside the plugin.dll file and then somthing tries to destroy that inside the application which I have told the app NOT to do, I have tried some type of smartpointers wich will only release the pointer and not destroy it, if I remove the std::list<..> and replace it with a single pointer to CShaderBase item and then I recive only one item from my plugin.dll file then everything works perfect.

Share on other sites
Link to the * DLL runtime libraries to fix the problem, like Multithreaded DLL rather than just Multithreaded. However this isn't the best solution, it is just covering up the problem. You should probably use something like com's Release(), but it doesn't have to be reference counting. It could just be:
class CShaderBase{   ...public:   virtual void Delete() = 0;};// OpenGL DLL:class COpenGLShader{   void Delete() { delete this; }};

That will delete from the correct heap.

Share on other sites
Quote:
 Original post by KibbleLink to the * DLL runtime libraries to fix the problem, like Multithreaded DLL rather than just Multithreaded. However this isn't the best solution, it is just covering up the problem. You should probably use something like com's Release(), but it doesn't have to be reference counting. It could just be:class CShaderBase{ ...public: virtual void Delete() = 0;};// OpenGL DLL:class COpenGLShader{ void Delete() { delete this; }};That will delete from the correct heap.

I have tried that... it still doesn't work as long as I have the pointer to the class inside a std::list<> container.. if I have only one pointer it works.

e.g.

This line doesn't work:

but if I replace that line with this it does

the retrive code looks like this at the moment

{

}

// this is called when engine is shutting down
DLL_API void ShutdownPlugin(void)
{
}

Share on other sites
You're not passing your std::list between the DLL and the app are you? Passing non-const STL containers over a DLL boundary is just asking for trouble.
You cannot add or remove objects to/from a STL container in both the DLL and the exe, you'll need some kind of accessors to do that.

Aside from that, I'm out of ideas about whats wrong.

Share on other sites
can I have a list in the .dll file which the .exe file can retrive using a function and then get the stuff from that list into it's own list?

e.g.

{
...

}

and then when I retrive the stuff I do this:

for( it .... )
{
exelist.push_back( (*it) );
}

dll_list = 0;

btw, how/where do I write in the const keyword on the function to make sure that it will return a const std::list<>?