On 08/01/2013 at 21:42, xxxxxxxx wrote:
Robert.
I've manged to get to the point where I can save String values into a scene's HF.
The changed string value sticks when the scene is saved and opened as expected without any problems.
But I'm getting access violation crashes when I try to do the same thing with a BaseBitmap.
You mentioned saving a copy of the bitmap. And I'm thinking that might be the final missing piece of the puzzle I need to make this finally work.
Could you please look at this code and let me know what you think?
#include "c4d.h"
#include "c4d_symbols.h"
#include "tsimpletag.h"
#include "customgui_priority.h" //needed for the priority stuff to work
// be sure to use a unique ID obtained from www.plugincafe.com
#define PLUGIN_ID 1000010
class SimpleTag : public TagData
{
INSTANCEOF(SimpleTag,TagData)
public:
BaseBitmap *bmp;
virtual Bool Read(GeListNode *node, HyperFile *hf, LONG level);
virtual Bool Write(GeListNode *node, HyperFile *hf);
virtual Bool CopyTo(NodeData* dest, GeListNode* snode, GeListNode* dnode, COPYFLAGS flags, AliasTrans* trn);
void createImage(void);
virtual Bool Message(GeListNode *node, LONG type, void *t_data);
virtual Bool Init(GeListNode *node);
virtual EXECUTIONRESULT Execute(BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, EXECUTIONFLAGS flags);
static NodeData *Alloc(void) { return gNew SimpleTag; }
};
Bool SimpleTag::Read(GeListNode *node, HyperFile *hf, LONG level)
{
return hf->ReadImage(bmp);
}
Bool SimpleTag::Write(GeListNode *node, HyperFile *hf)
{
hf->WriteImage(bmp,FILTER_JPG,NULL,SAVEBIT_0);
return TRUE;
}
Bool SimpleTag::CopyTo(NodeData* dest, GeListNode* snode, GeListNode* dnode, COPYFLAGS flags, AliasTrans* trn)
{
//What do I write here?
return TRUE;
}
void SimpleTag::createImage(void)
{
BaseDocument *doc = GetActiveDocument();
bmp = BaseBitmap::Alloc();
LONG x = 100; //The X size of the final image
LONG y = 100; //The Y size of the final image
bmp->Init(x, y);
RenderData *rd = doc->GetActiveRenderData(); //Get the active render data
BaseContainer rdcopy = rd->GetData();
rdcopy.SetLong(RDATA_XRES, x);
rdcopy.SetLong(RDATA_YRES, y);
rdcopy.SetLong(RDATA_RENDERENGINE, RDATA_RENDERENGINE_STANDARD);
RenderDocument(doc, rdcopy, NULL, NULL, bmp, RENDERFLAGS_EXTERNAL, NULL);
}
Bool SimpleTag::Message(GeListNode *node, LONG type, void *data)
{
BaseTag *tag = (BaseTag* )node; //Get the tag and assign it to a variable
BaseContainer *bc = ((BaseList2D* )node)->GetDataInstance(); //Get the container for the tag
switch (type)
{
case MSG_DESCRIPTION_COMMAND: // MSG_DESCRIPTION_COMMAND is sent when button is clicked
{
DescriptionCommand *dc = (DescriptionCommand* )data; // data contains the description ID of the button
LONG button = dc->id[0].id; // get the ID of the button
switch (button)
{
//This button executes a method that renders the scene into the bmp BaseBitmap variable
case BUTTON1:
createImage();
break;
//This button shows the current image stored in the bmp BaseBitmap variable in the image viewer
case BUTTON2:
ShowBitmap(bmp);
break;
}
}
}
tag->SetDirty(DIRTYFLAGS_DATA); //Used to update a Tag's AM GUI items
return TRUE;
}
Bool SimpleTag::Init(GeListNode *node)
{
bmp = NULL;
//This code sets up the expression priority options that most things have in c4d
GeData d;
if (node->GetParameter(DescLevel(EXPRESSION_PRIORITY),d,DESCFLAGS_GET_0))
{
PriorityData *pd = (PriorityData* )d.GetCustomDataType(CUSTOMGUI_PRIORITY_DATA);
if (pd) pd->SetPriorityValue(PRIORITYVALUE_CAMERADEPENDENT,GeData(FALSE));
node->SetParameter(DescLevel(EXPRESSION_PRIORITY),d,DESCFLAGS_SET_0);
}
return TRUE;
}
EXECUTIONRESULT SimpleTag::Execute(BaseTag *tag, BaseDocument *doc, BaseObject *op, BaseThread *bt, LONG priority, EXECUTIONFLAGS flags)
{
return EXECUTIONRESULT_OK;
}
Bool RegisterSimpleTag(void)
{
String path=GeLoadString(IDS_SIMPLETAG); if (!path.Content()) return TRUE;
return RegisterTagPlugin(PLUGIN_ID,path,TAG_EXPRESSION|TAG_VISIBLE,SimpleTag::Alloc,"tsimpletag",AutoBitmap("myicon.tif"),0);
}
The crash is coming from the Read() function when trying to open the saved file.
Thanks,
-ScottA