Main Index : Reference :
class BackupTags
{
public:
BackupTags();
[bool] Init([BaseObject] op);
[bool] Restore();
}
One should use this class whenever one is sending a message of the type MSG_POINTS_CHANGED, MSG_POLYGONS_CHANGED or MSG_SEGMENTS_CHANGED, else
one is not able to handle low memory conditions in C.O.F.F.E.E.
Imagine the following situation: You want to add just 1 point to a polygon object. Hence you allocate and initialize a VariableChanged class properly and send it to the object. Now the tags are reacting on the message and are resizing their data accordingly. But if one of the tags (for example the UVW tag) fails because of low memory conditions, the whole object is corrupted because some tags think the object contains n+1 points but some others (the UVW tag) think it has only n points. This is very likely to crash the editor and raytracer.
If one uses the class BackupTags, C4D will make a copy of all tags. Depending of the return value of MultiMessage() one can react and either just continue (if it's TRUE) or restore the tags (if it's FALSE). Of course one could write such a backup routine of one's own, but when restoring the tags one might run into troubles because the marker id of the tags has changed, which might mislead other plugins or functions in C4D. The BackupTags class will handle this correctly, so in case MultiMessage() returns FALSE one can get the original object back.
[bool] Init([BaseObject] op);
Backup the tags of object op. Returns TRUE if successful.
[bool] Restore();
Restores the tags of the backed up object. Returns TRUE if successful.
Example 1: Adding a point to a point object with BackupTags.
if (!instanceof(op,PointObject)) return FALSE; // Not a point object.
var vc = new(VariableChanged); if (!vc) return FALSE; // Allocate class.
var cnt = op->GetPointCount(); // Get actual point count.
vc->Init(cnt,cnt+1); // Resize point count from cnt to cnt+1.
// Just for adding a point at the end of
// the point list one doesn't need a map.
var bt = new(BackupTags); if (!bs) return FALSE; // Allocate a BackupTags object.
bt->Init(op); // Backup up 'op'
// Send the message to all tags and keys and let them return
// a boolean, telling us if everything is alright:
var ok = op->MultiMessage(MSG_POINTS_CHANGED,vc);
if (!ok)
{
bt->Restore(); // Restore the object if something went wrong
return FALSE;
}
// Now all tags and structures have reacted and resized their
// memory part, so one can access the new point:
op->SetPoint(cnt, p); // Set data p for new point
op->Message(MSG_UPDATE); // Notify object of change