BaseSelect->SelectAll() Freezing C4D.. [SOLVED]

On 14/05/2015 at 06:31, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R14+ 
Platform:   Windows  ;   
Language(s) :     C++  ;

---------
Hi,

I'm doing a final tidy-up of remaining code in my plugin and have noticed something which causes C4D to freeze..

My plugin is an ObjectData, registered with OBJECT_MODIFIER, and op->SetDeformMode(TRUE) is also set inside the MSG_MENUPREPARE of the Message function.

I have narrowed it down to the following code.  If i delete everything else inside my ModifyObject override and just have the following, it will freeze C4D by simply toggling between perspective viewport and four-views 3 or 4 times:

Bool MyPlugin::ModifyObject(BaseObject* mod, BaseDocument* doc, BaseObject* op, const Matrix& op_mg, const Matrix& mod_mg, Real lod, LONG flags, BaseThread* thread)
{
    PolygonObject* poly = ToPoly(op);
    BaseSelect* sel = poly->GetPolygonS();
    sel->SelectAll(0,poly->GetPolygonCount());
    return TRUE;
}

Can anybody confirm this or suggest a solution?

[edit]  Just to add, all i do is inside a fresh scene, create a cube, create my plugin deformer, and drag the deformer under the cube, then switch between perspective single view, and default four-views, a couple of times, and it freezes..

On 14/05/2015 at 06:36, xxxxxxxx wrote:

You try to select polygon that do not exist.

  
//max    The last element in the range to select!  
sel->SelectAll(0,poly->GetPolygonCount()-1);  
  

On 14/05/2015 at 06:39, xxxxxxxx wrote:

Opps, noob mistake 🙂

But it still freezes..

On 14/05/2015 at 06:50, xxxxxxxx wrote:

Of course you need to make sure that  'op' is really a PolygonObject using IsInstanceOf(Opolygon) and that everything is not nullptr.

On 14/05/2015 at 06:53, xxxxxxxx wrote:

You mean op?

Well using ToPoly on OP under a primitive object has been working 100% fine until i put SelectAll() inside the ModifyObject function..  And my test case is pretty simple, create a cube, drag deformer under it..

On 14/05/2015 at 07:21, xxxxxxxx wrote:

Hmm i think you are right..  When i use a cube thats converted to a mesh with CSTO it works fine..

Strange how i haven't came across this the entire time i've been developing this plugin..

I think i read in another recent thread using the cache is possible with primitives..

On 14/05/2015 at 09:26, xxxxxxxx wrote:

Yes of course I mean 'op'.
The code could look like this.

  
Bool MyPlugin::ModifyObject(BaseObject* mod, BaseDocument* doc, BaseObject* op, const Matrix& op_mg, const Matrix& mod_mg, Real lod, LONG flags, BaseThread* thread)  
{  
  if(op==nullptr) return FALSE;  
  if(op->IsInstanceOf(Opolygon)){  
      PolygonObject* poly = ToPoly(op);  
      BaseSelect* sel = poly->GetPolygonS();   
      if(sel==nullptr) return FALSE;  
      const Int32 polyCount = poly->GetPolygonCount();  
      if(polyCount > 0) {  
          sel->SelectAll(0,polyCount-1);  
      }  
      //....  
  }  
  return TRUE;  
}  

On 14/05/2015 at 10:31, xxxxxxxx wrote:

Thanks Remotion that's much appreciated.  I managed to get it working with the recursive function example in the code docs for GetCache(), but not sure if that's overkill at this point until i test further..

On 15/05/2015 at 08:53, xxxxxxxx wrote:

Hello,

I just want to point out that ToPoly() is no function but simply a macro. As you see in the documentation it only casts a BaseObject pointer to a PolygonObject pointer (and doesn't do anything) and should only applied when one really knows a given object is a polygon object.

Best wishes,
Sebastian