On 05/10/2016 at 10:59, xxxxxxxx wrote:
User Information:
Cinema 4D Version:
Platform: Windows ;
Language(s) : C++ ;
---------
Hi,
I'm writing an application using the Melange SDK. And I'm getting crashes when trying to copy more than one track using AppendCTrack().
In my app I have options to copy all tracks, just one, or a few of them.
Using the GetCTrackRoot() function I can copy all of them just fine. But copying just a few of them using the AppendCTrack() function crashes.
Here is a little example:
#include <windows.h>
#include <iostream>
using namespace std;
#include "c4d_file.h"
#include "default_alien_overloads.h"
using namespace melange;
#define APPID 1234567
void GetWriterInfo(Int32 &id, String &appname)
{
id = APPID;
appname = "My App";
}
const String sourceFile = "C:\\Users\\user\\Desktop\\source.c4d";
const String targetFile = "C:\\Users\\user\\Desktop\\target.c4d";
const Filename newFile = "C:\\Users\\user\\Desktop\\My Project.c4d";
int main(int argc, Char* argv[])
{
BaseDocument *sourceDoc = LoadDocument(sourceFile, SCENEFILTER_OBJECTS); if (!sourceDoc) return false;
BaseDocument *targetDoc = LoadDocument(targetFile, SCENEFILTER_OBJECTS); if (!sourceDoc) return false;
BaseObject *sourceObj = sourceDoc->GetFirstObject()->GetNext(); if (!sourceObj) return false;
BaseObject *targetObj = targetDoc->GetFirstObject(); if (!targetObj) return false;
//Copy all of the source object's tracks to the targt object
//This works fine
sourceObj->GetCTrackRoot()->CopyTo(targetObj->GetCTrackRoot(), COPYFLAGS_0, nullptr);
//Copy the rotation tracks from the source object to the target object
//Crashes if more than one of these is executed!!? ---OUCH!---
targetObj->AppendCTrack(sourceObj->FindCTrack(DescID(DescLevel(ID_BASEOBJECT_REL_ROTATION), DescLevel(VECTOR_X))));
targetObj->AppendCTrack(sourceObj->FindCTrack(DescID(DescLevel(ID_BASEOBJECT_REL_ROTATION), DescLevel(VECTOR_Y))));
targetObj->AppendCTrack(sourceObj->FindCTrack(DescID(DescLevel(ID_BASEOBJECT_REL_ROTATION), DescLevel(VECTOR_Z))));
//Save the results in a new c4d file
SaveDocument(targetDoc, newFile, SAVEDOCUMENTFLAGS_0);
system("pause");
return 0;
}
Why does the AppendCTrack() crash if more than one instance is called?
What is the proper way to copy multiple tracks from one object to another?
The target objects will most likely not have any existing tracks. But some might.
-ScottA