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

    VolumeData not thread safe even after copy[SOLVED]

    SDK Help
    0
    5
    488
    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 01/02/2016 at 17:09, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:    
      Platform:      
      Language(s) :

      ---------
      Hello! I want to implement multi processing for my VideoPostData plugin. It uses
      VolumeData::TraceGeometryEnhanced() and VolumeData::GetSurfaceData(). I tried
      to create a copy of the VolumeData before using these functions in the thread, but
      I still get access violations when I don't synchronize calls to these functions using a lock.

        // Create a copy of the VolumeData, it can not be accessed from
        // several threads simultaneously.
        lock_.Lock();
        AutoAlloc<VolumeData> vd;
        if (!vd) {
          lock_.Unlock();
          GePrint("Could not allocate VolumeData.");
          return;
        }
        info.vps->vd->CopyTo(vd);  // XXX does not return a value? How to check for success?
        lock_.Unlock();
      

      And later in the code

                lock_.Lock();
                vd->GetSurfaceData(&sd, false, false, false, true, &ray, si);  // <-- access violation if locking is removed
                lock_.Unlock();
      

      It used to work in a single threaded process. How do I correctly clone a VolumeData?

      Thanks in advance!
      Niklas

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

        On 02/02/2016 at 01:32, xxxxxxxx wrote:

        Hello,

        the Render class has the GetInitialVolumeData() function that apparently needs to be used to get the VolumeData structures for multiple threads.

        Best wishes,
        Sebastian

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

          On 02/02/2016 at 01:49, xxxxxxxx wrote:

          Thanks Sebastian, that's exactly what I needed. Sorry for not seeing it myself. :^)

          Could you provide some information on the "cpu_index" parameter of GetInitialVolumeData()? Like, is there
          a maximum value? Or will it just accept any value and make sure there is a unique VolumeData for that index?

          At the moment, I use vps->vd->GetCPUCount() and create that many threads and retrieve that many
          VolumeData's using GetInitialVolumeData() and that seems to work fine.

          Thanks,
          Niklas

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

            On 02/02/2016 at 05:58, xxxxxxxx wrote:

            Also VolumeData that was returned by GetInitialVolumeData() is not the same as  vps->vd and is required by InitRende() for example.

            What would be interesting is to if one can clone them using CopyTo().

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

              On 03/02/2016 at 01:29, xxxxxxxx wrote:

              Hello,

              the CPU index must be smaller than the number of initiated threads. GetInitialVolumeData() does not create new copies of the VolumeData but provides access to already existing instances.

              The number of threads depends on the CPU count that can be obtained with VolumeData::GetCPUCount().

              Best wishes,
              Sebastian

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