Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    About threads

    Cinema 4D SDK
    c++ r20
    2
    4
    1.2k
    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.
    • A
      anoano
      last edited by s_bach

      Hello

      The around thread becomes new from R20 and it does not work with the old code.
      I am trying while looking at the SDK sample, but it does not move with an error.

      No 1 error
      An operator that handles the right operand of maxon :: ResultMemT <maxon :: BaseRef <IMPLEMENTATION, maxon :: StrongRefHandler >> 'can not be found (or can not be converted).

      class MyThread : public maxon::ThreadInterfaceTemplate<MyThread>
      {
      public:
      const char* GetName() const { return "MyThread"; }
      maxon::Result<void> operator ()()
      {
      GePrint("ok"_s);
      }
      };

      class MenuTest : public CommandData
      {
      static maxon::ThreadRefTemplate<MyThread> g_test;
      public:
      virtual Bool Execute(BaseDocument
      doc);
      };

      Bool MenuTest::Execute(BaseDocument doc)
      {
      if (!g_test) g_test = MyThread::Create() iferr_return; // No1 Error
      }

      Please tell me if you can understand.

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by s_bach

        Hello,

        there are a few issues with the code you posted.

        First, please make sure to use the correct function declarations. CommandData::Execute() is defined as

        Execute(BaseDocument* doc)
        

        The doc argument is a pointer, not a copy.

        Second, please pay attention to return values. The Execute() function must return a Bool value. The operator()() of the thread must return a maxon::Result<void>.

        In the Execute() function you create a thread instance. You must handle the error object returned by the Create() function.

        There are multiple ways to handle such error values. You find examples in the Error Handling manual.

        One way would be to use iferr_scope_handler. With that the Execute() function can look like this:

        Bool MenuTest::Execute(BaseDocument* doc)
        {
          iferr_scope_handler
          {
            err.DiagOutput();
            err.DbgStop();
            return true;
          };
        
          if (!g_test)
          {
            g_test = MyThread::Create() iferr_return; 
          }
        
          return true;
        }
        

        The worker function (operator()()) of the thread must return a Result<void> object. This is typically maxon::OK when everything is OK. You find an example of such a custom thread in the Threads Manual.

        Some more hints:

        • for new code please use ApplicationOutput() instead of GePrint(). See API Transition.
        • when posting code please use the Markdown syntax. See also Markdown summary.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • A
          anoano
          last edited by

          Hi.

          Thank you for teaching me.
          I am not sure of the new maxon API Threading.
          Are there samples of jobs and Threads?

          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by s_bach

            Hello,

            you find information and examples on jobs and threads in these manuals:

            • Jobs Manual
            • Threads Manual

            best wishes,
            Sebastian

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

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