Display control
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/08/2003 at 05:07, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.100
Platform:
Language(s) : C++ ;---------
How does Display Control work ??
I tried using this codeclass TestToolData : public ToolData { public: virtual Bool InitTool(BaseDocument* doc, BaseContainer& data, BaseThread* bt); virtual void FreeTool(void); virtual Bool MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg); virtual LONG GetState(BaseDocument *doc); virtual Bool GetCursorInfo(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, Real x, Real y, BaseContainer &bc); virtual LONG Draw(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, BaseDrawHelp *bh, BaseThread *bt,LONG flags); virtual Bool InitDisplayControl(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, AtomArray* active); virtual void FreeDisplayControl(void); virtual Bool DisplayControl(BaseDocument* doc, BaseObject* op, BaseObject* chainstart, BaseDraw* bd, BaseDrawHelp* bh, ControlDisplayStruct& cds); virtual SubDialog* AllocSubDialog(BaseContainer* bc); private: Vector *color; }; Bool TestToolData::InitTool(BaseDocument* doc, BaseContainer& data, BaseThread* bt) { GePrint("InitTool"); return TRUE; } void TestToolData::FreeTool(void) { GePrint("FreeTool"); } LONG TestToolData::GetState(BaseDocument *doc) { GePrint("Get State"); if (doc->GetMode()==Mpaint || !doc->GetActiveObject() || !doc->GetActiveObject()->IsInstanceOf(Opolygon)) return 0; return CMD_ENABLED; } Bool TestToolData::InitDisplayControl(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, AtomArray* active) { GePrint("Init Display Control"); color = NULL; BaseObject *op = doc->GetActiveObject(); if(!op) return TRUE; if(!op->IsInstanceOf(Opolygon)) return TRUE; Polygon *poly = ToPoly(op)->GetPolygon(); LONG pcnt = ToPoly(op)->GetPolygonCount(); Vector *vert = ToPoly(op)->GetPoint(); LONG vcnt = ToPoly(op)->GetPointCount(); color = (Vector* )GeAlloc(sizeof(Vector)*vcnt); // now i calculate the colors return TRUE; } void TestToolData::FreeDisplayControl(void) { GePrint("Free Display Control"); GeFree(color); } Bool TestToolData::DisplayControl(BaseDocument* doc, BaseObject* op, BaseObject* chainstart, BaseDraw* bd, BaseDrawHelp* bh, ControlDisplayStruct& cds) { GePrint("DisplayControl"); if(!(op && op==doc->GetActiveObject() && op->IsInstanceOf(Opolygon)) return TRUE; cds.vertex_color = color; cds.backface_culling = FALSE; return TRUE; }
This crashes all the time. To be more precise, it crashes when i want to modify the points of the mesh using any other tool.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/08/2003 at 17:07, xxxxxxxx wrote:
Hi Michael,
it crashes here already when trying to rotate the view.
The freeing of the allocated vector array in FreeDisplayControl() performs the crash. (though I don´t understand why either cause it should work IMO) Free it in FreeTool() and it will work.
Hope that helps
Samir -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/08/2003 at 17:11, xxxxxxxx wrote:
And I just tested it, it does seem to free the allocated memory itself. But I wouldn´t say this is safe at all. Very odd...
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/08/2003 at 01:14, xxxxxxxx wrote:
Indeed very odd...
but if you don't get memory leaks and it doesn't crash.. i guess it is alright
Thanks for testing -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/08/2003 at 05:28, xxxxxxxx wrote:
Wait... i get memory leaks whenever i change the object or switch tools.
Obviously these functions are either buggy or much too complicated to use. I better don't use them. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/08/2003 at 08:33, xxxxxxxx wrote:
hmm, as I said, maybe not safe Sorry, cannot help you further here. Surely, Mikael can tell you more than I can.
Good luck! -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/08/2003 at 06:47, xxxxxxxx wrote:
i got it now
memory for the colors has to be allocated whenever DisplayControl is called. C4d takes ownership of the memory. Trying to free the colors again was wrong.
And second the PLUGINFLAG_TOOL_FORCESHADING must be set when registering the tool. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/08/2003 at 10:46, xxxxxxxx wrote:
As far as I've been told C4D should allocate the array for you. When the array in the structure is NULL vertex coloring is disabled. Please try if it wasn't just that PLUGINFLAG_TOOL_FORCESHADING wasn't set. (I haven't verified this myself.)
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 07/08/2003 at 13:58, xxxxxxxx wrote:
Can't confirm here. cds.vertex_color is NULL. If i allocate the mem it works.