THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/08/2006 at 10:42, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 9.603
Platform: Windows ;
Language(s) : C++ ;
---------
Hi all
i try to make a copy paste system for polygons.
And i'm having some stability problems.
Here is the code of the "copy" part. Sorry, i couln't simplify it anymore so that it still crashes.
#include "c4d.h"
#include "c4d_symbols.h"
struct Clipboard
{
~Clipboard() { TakeObjects(NULL); }
AutoAlloc<AtomArray> array;
void TakeObjects( AtomArray* a );
};
void Clipboard::TakeObjects( AtomArray* a )
{
if( !array ) return;
// free all stored objects
array->FilterObjectChildren();
for( LONG i=0; i<array->GetCount(); ++i )
{
BaseObject* op = static_cast<BaseObject*>( array->GetIndex(i) );
BaseObject::Free( op );
}
array->Flush();
GeAssert( array->GetCount()==0 );
// copy pointers from a to array
if( a ) a->CopyTo( array );
}
static Clipboard *g_clip = NULL;
void FreeClipboard()
{
gDelete( g_clip );
}
Clipboard* GetClipboard()
{
if( !g_clip ) {
g_clip = gNew Clipboard;
}
return g_clip;
}
Bool DoCopy( BaseDocument* doc )
{
Clipboard* clip = GetClipboard();
if( !clip ) return TRUE;
AutoAlloc<AtomArray> active;
doc->GetActivePolygonObjects( *active, TRUE );
if( active->GetCount()>0 )
{
ModelingCommandData md;
md.op = NULL;
md.arr = active;
md.doc = doc;
md.result = NULL;
md.mode = 0;
md.flags = 0;
md.result = NULL;
SendModelingCommand( MCOMMAND_SPLIT, md );
clip->TakeObjects( md.result );
}
else clip->TakeObjects( NULL );
return TRUE;
}
class MenuTest : public CommandData
{
public:
virtual Bool Execute(BaseDocument *doc);
};
Bool MenuTest::Execute(BaseDocument *doc)
{
DoCopy( doc );
return TRUE;
}
Bool RegisterMenuTest(void)
{
// decide by name if the plugin shall be registered - just for user convenience
String name=GeLoadString(IDS_MENUTEST); if (!name.Content()) return TRUE;
// be sure to use a unique ID obtained from www.plugincafe.com
return RegisterCommandPlugin(1000956,name,0,"icon.tif","C++ SDK Menu Test Plugin",gNew MenuTest);
}
//In main.cpp:
void FreeClipboard();
void PluginEnd(void)
{
FreeClipboard();
}
This code can crash reproducable when you do the following:
Create c4d_debug.txt file, so C4d runns in debug mode.
Run C4d.
Make a cube.
Make Editable.
Make a HNWeightTag ( use hn weight tool on some edges )
Select some polys
Call the plug
Quite Cinema
...
BOOM... wtf..
it only crashes if you run in debug mode, and have the HN tag. I suspect some memory becomes corrupted somehow.
Okay this crash happens when you quit. But i'm also having other crashes which are harder to reproduce.
I have no idea what is going on. Help ??!!