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

    Gradient crash

    SDK Help
    0
    10
    1.1k
    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 26/10/2016 at 19:42, xxxxxxxx wrote:

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

      ---------
      This is a weird one.

      I'm trying to add a Gradient to a Description, but on OSX it just seems to crash C4D. My code is pretty simple and is basically doing something like:

      BaseContainer bc = GetCustomDataTypeDefault(CUSTOMDATATYPE_GRADIENT);
      bc.SetInt32(DESC_CUSTOMGUI, CUSTOMGUI_GRADIENT);
      bc.SetString(DESC_SHORT_NAME, "Gradient");
      bc.SetString(DESC_NAME, "Gradient");
      .
      .
      .
      

      I tried looking at the stack trace, but it looks kind of useless, unfortunately.

      If I take the exact code snippet over to Windows, then it works as expected. Can someone else replicate the crash on OSX? Am I just doing something wrong?

      Thanks,
      Ian

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

        On 27/10/2016 at 01:18, xxxxxxxx wrote:

        Hello,

        right now I cannot reproduce any problems with creating and using a Gradient parameter (macOS, Xcode7, R18). The code I'm using is this:

          
        DescID gradiendID = DescLevel(2000, CUSTOMDATATYPE_GRADIENT, 0);  
          
        // define the new parameter description  
        BaseContainer gradient = GetCustomDataTypeDefault(CUSTOMDATATYPE_GRADIENT);  
        gradient.SetBool(DR_COLORFIELD_ICC_BASEDOC, true);  
        gradient.SetString(DESC_SHORT_NAME, "gradient");  
        gradient.SetInt32(DESC_CUSTOMGUI, CUSTOMGUI_GRADIENT);  
        // set the new parameter  
        desc->SetParameter(gradiendID, gradient, ID_OBJECTPROPERTIES);  
        

        Can you tell us what exactly is the context of your code? In what kind of plugin are you using it? Can you post your complete implementation of GetDDescription()?

        best wishes,
        Sebastian

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

          On 27/10/2016 at 09:21, xxxxxxxx wrote:

          In case it matters, I'm using Xcode 6.2 (6C131e), OSX 10.9.5, Mavericks.

          This is being done in a TagData class. The tag is getting attached to a light object. Our GetDDescription is a little more involved than this, but it essentially looks like this:

          Bool LightFilterTagData::GetDDescription(GeListNode* node, Description* description, DESCFLAGS_DESC& flags)
          {
              if (!description->LoadDescription("Trmlightfilter")) return false;  
              flags |= DESCFLAGS_DESC_LOADED;
            
              Int32 shaderID = 11248329; 
              Int32 paramsStart = 2000; 
              Int32 paramsOffset = 10;
              Int32 paramID = 0;    
              BaseContainer bc;
              Int32 type = NOTOK;
               type = CUSTOMDATATYPE_GRADIENT;
               bc = GetCustomDataTypeDefault(CUSTOMDATATYPE_GRADIENT);
               bc.SetString(DESC_SHORT_NAME, "Gradient");
               bc.SetString(DESC_NAME, "Gradient");     
              bc.SetInt32(DESC_CUSTOMGUI, CUSTOMGUI_GRADIENT);
            
              DescID cid = DescID(DescLevel(shaderID, DTYPE_SUBCONTAINER, 0), DescLevel(paramsStart + paramID * paramsOffset, type, 0));
          description->SetParameter(cid, bc, DescID(ID_TAGPROPERTIES));
            
          return SUPER::GetDDescription(node, description, flags);
          }
          

          In the real code, shaderID is being generated by a hash function based on node. We're adding the parameters in a loop, with paramID  increasing by 1 with each step.

          I don't know if there are other custom UI's that will crash, but if I switch the code to use CUSTOMGUI_STRINGMULTI i.e.:

          type = DTYPE_STRING;
          bc = GetCustomDataTypeDefault(DTYPE_STRING);
          bc.SetInt32(DESC_CUSTOMGUI, CUSTOMGUI_STRINGMULTI);
          

          then I don't get a crash.

          Thanks,
          Ian

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

            On 28/10/2016 at 00:56, xxxxxxxx wrote:

            Hello,

            I can't reproduce any problems with the code you have given. Can you debug your code to see where exactly the crash happens? Does it crash inside GetDDescription() or somewhere else?

            Technically you don't have to set the custom GUI in this case since the gradient custom GUI ist the default GUI of the gradient data type.

            best wishes,
            Sebastian

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

              On 29/10/2016 at 13:45, xxxxxxxx wrote:

              Hi Sebastian,

              Sorry, it looks like my example code to you was not complete. There should have been code that filled in a DESC_CYCLE right before the gradient. So it looks like this:

              Bool LightFilterTagData::GetDDescription(GeListNode* node, Description* description, DESCFLAGS_DESC& flags)
              {
                  if (!description->LoadDescription("Trmlightfilter")) return false;  
                  flags |= DESCFLAGS_DESC_LOADED;
                
                  BaseContainer *shaderDesc = description->GetParameterI(DescLevel(10001), NULL);
                  if (shaderDesc)
                  {
                      BaseContainer *shaderCycle = shaderDesc->GetContainerInstance(DESC_CYCLE);
                      if (shaderCycle)
                      {
                          shaderCycle->FlushAll();
                          Int name = 0;
                          for (size_t iShader = 0; iShader < 2; ++iShader, ++name)
                          {
                              shaderCycle->SetString((Int32)iShader, String::IntToString(name));
                          }
                      }
                  }
                
                  Int32 shaderID = 11248329; 
                  Int32 paramsStart = 2000; 
                  Int32 paramsOffset = 10;
                  Int32 paramID = 0;    
                  BaseContainer bc;
                  Int32 type = NOTOK;
                   type = CUSTOMDATATYPE_GRADIENT;
                   bc = GetCustomDataTypeDefault(CUSTOMDATATYPE_GRADIENT);
                   bc.SetString(DESC_SHORT_NAME, "Gradient");
                   bc.SetString(DESC_NAME, "Gradient");     
                  bc.SetInt32(DESC_CUSTOMGUI, CUSTOMGUI_GRADIENT);
                
                  DescID cid = DescID(DescLevel(shaderID, DTYPE_SUBCONTAINER, 0), DescLevel(paramsStart + paramID * paramsOffset, type, 0));
              description->SetParameter(cid, bc, DescID(ID_TAGPROPERTIES));
                
              return SUPER::GetDDescription(node, description, flags);
              }
              

              If I edit the code to only have one item in the cycle, then it doesn't crash. So it has something to do with having both the cycle and the gradient together that's crashing for me.

              Thanks,
              Ian

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

                On 31/10/2016 at 03:03, xxxxxxxx wrote:

                Hello,

                I still can't reproduce any problems. You could try to add the suspect code to an existing example of the cinema4dsdk to see if it causes a crash there. This way we would now what change exactly is needed to reproduce the crash.

                best wishes,
                Sebastian

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

                  On 01/11/2016 at 08:08, xxxxxxxx wrote:

                  OK, I'll try to get you a complete example. It might take a while as I'm fighting another issue at the moment.

                  Thanks,
                  Ian

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

                    On 02/11/2016 at 13:22, xxxxxxxx wrote:

                    I think I know what the difference might be.

                    Lately, I've been starting C4D from lldb for debugging purposes. It looks like it only crashes when running C4D this way. If I run C4D normally, then there's no crash and I get a nice gradient. This may also explain why I wasn't seeing the crash on Windows, since I wasn't running in the debugger there.

                    I've actually noticed this behavior with other things in C4D outside of our plugin. For example, if I create a MoText and nest a PolyFX underneath it and try to save the scene, whilst in the debugger, then it crashes C4D. If I run C4D normally, then, again, no crash.

                    Thanks,
                    Ian

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

                      On 03/11/2016 at 01:37, xxxxxxxx wrote:

                      Hello,

                      are you sure your Gradient crashes? The second example about the MoText does not crash. It "only" triggers a few breakpoints.

                      best wishes,
                      Sebastian

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

                        On 03/11/2016 at 15:01, xxxxxxxx wrote:

                        Ah, yes, you are right. They are breakpoints, not crashes.

                        Ian

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