Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

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

    SDK Help
    0
    9
    750
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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..

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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);  
          
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

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

          Opps, noob mistake 🙂

          But it still freezes..

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              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..

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                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..

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  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;  
                  }  
                  
                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    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..

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post