So in the end for the UI workflow this seems to work but it skips some of the steps, like linking to the BaseContainer*
, you proposed in the last post. Capturing the links by reference was also causing the issues with the GetLink()
calls I had mentioned and if lots of copies were made we'd crash in the BaseLink::Free()
call.
BaseLink *objectLink = BaseLink::Alloc();
if (objectLink != nullptr) {
objectLink->SetLink(object);
auto copySettingsLambda = [objectLink, document]() -> void {
if (objectLink != nullptr) {
BaseObject* myObject = static_cast<BaseObject*>(objectLink->GetLink(document));
if (myObject != nullptr) {
// SetAtomParamter<> calls with myObject
}
BaseLink* toDelete = objectLink;
BaseLink::Free(toDelete);
}
};
maxon::ExecuteOnMainThread(copySettingsLambda, false);
}
And for the Material workflow the lambda captures a different BaseObject* myObject
, which has a link in its description to the Material I want to insert in the document. I wasn't able to just link the material in the BaseLink.
BaseLink *materialLink= BaseLink::Alloc();
if (materialLink!= nullptr) {
materialLink->SetLink(myObject);
auto insertMaterialLambda= [materialLink, document]() -> void {
if (materialLink!= nullptr) {
BaseObject* myObject = static_cast<BaseObject*>(materialLink->GetLink(document));
if (myObject != nullptr) {
BaseMaterial* material= getAtomBaseLink<BaseMaterial>(*myObject, MATERIAL_ID, document).GetValue();
if(material != nullptr) {
document->insertMaterial(material);
}
BaseLink* toDelete = material;
BaseLink::Free(toDelete);
}
}
};
maxon::ExecuteOnMainThread(copySettingsLambda, false);
}
Do you think this is safe now compared to the original capturing of the BaseObject*
object ? Stressing it a lot and it doesn't seem to crash (although it also wasn't crashing with the original solution)
Many thanks for the attention,
Georgi.