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
    • Recent
    • Tags
    • Users
    • Login

    MCOMMAND_TRIANGULATE vs. hair

    Scheduled Pinned Locked Moved SDK Help
    8 Posts 0 Posters 521 Views
    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 Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 23/11/2008 at 14:36, xxxxxxxx wrote:

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

      ---------
      Hello all,
      I am exporting the document using a Hierarchy derivative and I am encountering an intermittent crash in hair.cdl in my Hierarchy::Do method. What happens is this: after the passed object has been checked and confirmed to be a non-null Opolygon, I place it in a temporary document and then call SendModelingCommand with MCOMMAND_TRIANGULATE. Upon making this call there is sometimes a crash with a _BugReport.txt trace that ends in hair.cdl. At that point, maybe the Hierarchy has gotten through 10 objects, and maybe it has gotten through 500 - there is no pattern that I can see yet. I have tried using any number of different options in the hair object's Generate tab (I need polygons) but it doesn't seem to make any difference (well, I haven't seen a problem when Single Object is enabled). I am even checking that the PolygonObject::GetPoint() and GetPointCount() are non-null/zero before I try to triangulate, just in case that could cause an issue.
      I am looking through as much of the documentation as I can and I don't see any special concerns noted for this scenario. This is happening in the context of a blocking thread, so there shouldn't be any issues there. I have not yet sent in any of the bug reports, since I am not sure if there is something I should/shouldn't be doing to cause this. Any input would be appreciated.
      Thanks,
      JD

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 24/11/2008 at 01:05, xxxxxxxx wrote:

        Please post some code, thanks.

        cheers,
        Matthias

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 24/11/2008 at 14:12, xxxxxxxx wrote:

          Okay, I tried to simplify this as much as possible and it turns out that it doesn't seem to be related to SendModelingCommand at all. Of course, I'm pretty much in the dark since it's not crashing anywhere inside my own code. Rather, it seems more that in the context of Hierarchy::Do, simply taking an object out of its document, then putting it back causes a crash later on. On that assumption, I tried NOT putting it in a temp document, and this has some success, but still crashes randomly in hair.cdl. So, if I can't remove/re-insert the object, and if I can't modify it while it's in its own document, then I suppose I will just have to clone it, or triangulate it manually?

              
              
              
              
              #include <c4d.h>  
              #include <c4d_symbols.h>
              
              
              
              
              static LONG count;
              
              
              
              
              class TestHierarchy : public Hierarchy  
              {
              
              
              
              
              public:
              
              
              
              
                  virtual void *Alloc(void) { return 0; }  
                  virtual void Free(void *data) { }  
                  virtual void CopyTo(void *src, void *dst) { }
              
              
              
              
                  Bool CrashRandomlyDuringRun(PolygonObject* polyObj)  
                  {  
                      // since removing and replacing objects during  
                      // Hierarchy::Do seems to cause a crash, I   
                      // also tried without using a temp document  
                        
                      BaseDocument* oDoc = polyObj->GetDocument(); 
              
              
              
              
                      ModelingCommandData mcd;  
                      mcd.op   = polyObj;  
                      mcd.doc  = oDoc;  
                      return SendModelingCommand(MCOMMAND_TRIANGULATE, mcd);  
                  }
              
              
              
              
                  Bool CrashAtEndOfRun(PolygonObject* polyObj)  
                  {  
                      AutoAlloc<BaseDocument> tmpDoc;  
                      if (!tmpDoc) return FALSE;
              
              
              
              
                      BaseDocument* oDoc = polyObj->GetDocument();   
                      BaseObject*   up   = polyObj->GetUp();  
                      BaseObject*   pred = polyObj->GetPred();
              
              
              
              
                      polyObj->Remove();  
                      tmpDoc->InsertObject(polyObj, 0, 0, 0);
              
              
              
              
                      // no need to use SendModelingCommand here, it seems  
                      // that just removing and re-inserting the object is   
                      // enough to cause a crash at the end of Hierarchy::Run
              
              
              
              
                      polyObj->Remove();  
                      if (oDoc) oDoc->InsertObject(polyObj, up, pred, 0);
              
              
              
              
                      return TRUE;  
                  }
              
              
              
              
                  virtual Bool Do(void *data, BaseObject *op, const Matrix &mg, Bool controlobject)  
                  {  
                      if (controlobject) return TRUE;  
                      if (!(op && op->GetType() == Opolygon)) return TRUE;
              
              
              
              
                      PolygonObject* polyObj = static_cast<PolygonObject*>(op);
              
              
              
              
                      StatusSetText(String("processing # ") + LongToString(count++));  
                        
                      // this method may cause a crash  
                      //return CrashRandomlyDuringRun(polyObj);  
                        
                      // this method will cause a crash  
                      //return CrashAtEndOfRun(polyObj);  
                  }
              
              
              
              
              };
              
              
              
              
              #define ID_TEST 1000000
              
              
              
              
              class TestCommand : public CommandData  
              {
              
              
              
              
              public:
              
              
              
              
                  virtual Bool Execute(BaseDocument *doc)    
                  {   
                      count = 0;  
                      TestHierarchy th;         
                      StatusSetText("running test...");  
                      Bool ret = th.Run(doc, FALSE, 1.0, VFLAG_EXTERNALRENDERER, 0, 0);  
                      StatusSetText("success.");  
                      return ret;  
                  }
              
              
              
              
                  virtual LONG GetState(BaseDocument *doc)   
                  {   
                      return CMD_ENABLED;   
                  }
              
              
              
              
              };
              
              
              
              
              Bool RegisterTestCommand(void)  
              {     
                  return RegisterCommandPlugin( ID_TEST, "Test", 0, "Test", gNew TestCommand);   
              }
              
              
              
          
          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 24/11/2008 at 15:32, xxxxxxxx wrote:

            Looks like cloning is out too - again I am picking up a random crash in hair.cdl; here's another Hierarchy::Do method that will cause this:

                
                
                
                
                    virtual Bool Do(void *data, BaseObject *op, const Matrix &mg, Bool controlobject)  
                    {  
                        if (controlobject) return TRUE;  
                        if (!(op && op->GetType() == Opolygon)) return TRUE;
                
                
                
                
                        BaseObject* clone = (BaseObject* )(op->GetClone(0, 0));  
                        if (clone) BaseObject::Free(clone);
                
                
                
                
                        return TRUE;  
                    }
                
                
                
            

            Here's part of the trace, which looks pretty much the same as the ones I am seeing with SendModelingCommand:

                
                
                
                
                 Exception  
                 {  
                  ExceptionNumber = 0xC0000005  
                  ExceptionText = "ACCESS_VIOLATION"  
                  Address = 0x0AA1F8E1  
                  Thread = 1688  
                  Last_Error = 0x00000000  
                 }  
                 Call_Stacks  
                 {  
                  Call_Stack_Thread_1688  
                  {  
                   hair.cdl: 0AA1F8E1  
                   CINEMA 4D.EXE: 00722CE4  
                   CINEMA 4D.EXE: 00947E2B  
                   CINEMA 4D.EXE: 00997D0C  
                   CINEMA 4D.EXE: 0094BC95  
                   CINEMA 4D.EXE: 00997C4E  
                   CINEMA 4D.EXE: 0090EF7C  
                   CINEMA 4D.EXE: 0094BC95  
                   CINEMA 4D.EXE: 00919F56  
                   CINEMA 4D.EXE: 00B77386  
                   CINEMA 4D.EXE: 00B1AA5B  
                   CINEMA 4D.EXE: 0094BD0B  
                   CINEMA 4D.EXE: 00919CA9  
                   [my_plugin].cdl: 0B04579C C4DAtom::GetClone  
                   [my_plugin].cdl: 0B04586F TestHierarchy::Do  
                   [my_plugin].cdl: 0B25FBBD HDo  
                   [etc...]
                
                
                
            

            I'm on a 3.8GHz dual Xeon running XP Pro x86 SP3 here. I'll send in some bug reports if you think this is looking like it's a Cinema issue. To clarify, I am seeing two apparently-unrelated issues:
            1. remove/re-insert an object from its document in Hierarchy::Do seems to upset the internal workings of Hierarchy, causing it to crash at the end of its Run method
            2. SendModelingCommand and GetClone are randomly causing crashes in hair.cdl when called in the context of Hierarchy::Do
            Thanks,
            JD

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 26/11/2008 at 02:36, xxxxxxxx wrote:

              The problem is you modify the document used by the Hierarchy class. If you want to modify the polygonal object you have to insert a clone of the object into a temporary document. Here some working code:

              > \> class ExampleHierarchy : public Hierarchy \> { \>      public: \>           virtual void \*Alloc(void) { return NULL; } \>           virtual void Free(void \*data) { } \>           virtual void CopyTo(void \*src, void \*dst) { } \>           virtual Bool Do(void \*data, BaseObject \*op, const Matrix &mg;, Bool controlobject); \> \>           Bool NoCrashAtEndOfRun(PolygonObject\* polyObj); \> }; \> \> Bool ExampleHierarchy::Do(void \*data, BaseObject \*op, const Matrix &mg;, Bool controlobject) \> { \>      if(!op) return FALSE; \> \>      if (controlobject) return TRUE; // this object is not visible, has been used by generator \>      if (op->GetType() != Opolygon) return TRUE; // we can't use this \> \>      return NoCrashAtEndOfRun(ToPoly(op)); \> } \> \> Bool ExampleHierarchy::NoCrashAtEndOfRun(PolygonObject\* polyObj) \> { \>      AutoAlloc<BaseDocument> tmpDoc; \>      if (!tmpDoc) return FALSE; \> \>      PolygonObject \*tmpObj = NULL; \>      tmpObj = (PolygonObject\* )polyObj->GetClone(COPY_NO_HIERARCHY|COPY_NO_ANIMATION|COPY_NO_BITS, NULL); \>      if(!tmpObj) return FALSE; \> \>      tmpDoc->InsertObject(tmpObj, NULL, NULL, FALSE); \> \>      ModelingCommandData mcd; \>      mcd.op   = tmpObj; \>      mcd.doc = tmpDoc; \>       \>      return SendModelingCommand(MCOMMAND_TRIANGULATE, mcd); \> } \> \> \> class MenuTest : public CommandData \> { \>      public: \>           virtual Bool Execute(BaseDocument \*doc); \> }; \> \> Bool MenuTest::Execute(BaseDocument \*doc) \> { \>      StopAllThreads(); \> \>      ExampleHierarchy eh; \> \>      return eh.Run(doc, FALSE, 1.0, VFLAG_EXTERNALRENDERER, NULL, NULL); \> } \>

              Btw. your code is not only crashing with Hair but with other objects as well.

              cheers,
              Matthias

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

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 26/11/2008 at 06:25, xxxxxxxx wrote:

                Thanks for the reply, but apparently you didn't read my last post. Your example is basically identical and it crashes too (tested on R9.603 and R11.012). As I said, the crash is random - you may get through a few test runs, but eventually it will crash. In testing, make sure your Hierarchy is not just re-iterating the same cache - simply clicking in a viewport should be enough to invalidate the cache after a successful test. Here I can generally get through two or three runs before it faults.
                JD

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

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 26/11/2008 at 06:46, xxxxxxxx wrote:

                  Sorry I had somehow overlooked you mentioning cloning objects.

                  Unfortunatly I can not confirm the crash with a cloned object. Please attach a scene if possible.

                  Btw, does it crash with exact the same code I provided?

                  cheers,
                  Matthias

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

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 26/11/2008 at 07:22, xxxxxxxx wrote:

                    Yes, it crashes with your exact code cut & pasted just to avoid any small difference. However, at this time I am only interested now in finding out why GetClone has an issue, so I prefer to remove any code related to SendModelingCommand - there should be no reason to think it will present any problem once I can actually get a clone of the object without crashing.
                    I'm not sure how to attach a file on this forum, but it is easy to duplicate the test document I'm using:

                    • open Cinema
                    • Objects > Primitive > Sphere
                    • Hair > Add Hair
                    • Hair > Generate > Type: Flat
                    • Hair > Generate > Advanced > Single Object: un-checked
                    • run ExampleHierarchy
                    • if successful, click in viewport and run again
                    • repeat until crash

                    If you still can't get it to crash, I'll have to go through and check my compiler/linker settings once again - are you aware of any in particular which might cause an issue?
                    JD

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