THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/05/2010 at 01:46, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R11
Platform: Windows ;
Language(s) : C++ ;
---------
Hey everyone,
my name is Heinrich Löwe, im working for Sehsucht GmbH in Hamburg. Me and a workmate(Martin Chatterjee) are working on a multi-platform-exchange format. For this reason we have written a DLL library which containes the basic functionality. It is imported in plugins for various applications and c4d is one of them.
I don't want to bore anyone with more details and will get straight to the point: The DLL is exporting functions which modify references to STL containers. If i use these functions in a C4D plugin, it always leads to crashes. However, they work fine with a direct inlcude of the code or in different environments than c4d.
I've boiled down the code to show you the main point:
Parts of the DLL library which are responsible for the problems:
// ...
// define a dll import/export macro
#ifdef DLL_TEST_EXPORTS
#define DLL_MACRO __declspec(dllexport)
#else
#define DLL_MACRO __declspec(dllimport)
#endif
// ...
// A representative structure exporting a stl container
struct DLL_MACRO MyStruct {
template class DLL_MACRO allocator<int>;
template class DLL_MACRO vector<int, allocator<int> >;
vector<int> vec;
};
// ...
// Global function which modifies the given reference
void DLL_MACRO GlobalFunction(vector<MyStruct> &vec;)
{
// just do something with the input
vec.resize(10);
}
// ...
Now the usage of the exported function in the C4D plugin code:
// ...
// code is executed during the c4d startup phase, while
// registering the plugin.
Bool Register_MyTestPlugin(void)
{
// create some stl container, using the exported structure
vector<MyStruct> *b = gNew vector<MyStruct>;
// call exported function which modifies my stl container
GlobalFunction(*b);
// kill it, at this point the plugin crashes
/////////////////////////////////////////////////////////
gDelete(b);
/////////////////////////////////////////////////////////
// ...
return TRUE;
}
// ...
While running that plugin in debug mode everything works, up to the point where the vector is deleted. I tracked it further down to a call to C4DOS.Ge->Free() in the overloaded delete operator in the file 'c4d_memory.cpp'.
Thas is the point where i got stuck and i'm hoping for your assistance to solve the problem,
Thanks,
Heinrich Löwe.