Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

R18 crashes at CreatePhongNormals() on othe thread

 Post Reply Post Reply
Author
Message
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Topic: R18 crashes at CreatePhongNormals() on othe thread
    Posted: 2017 Sep 25 at 4:42pm

User Information:

Cinema 4D Version:   R18 
Platform:   Windows  ;   
Language(s):     C++  ;   

---------

Hi All!

I have found an unpleasant thing.
R18 crashes if I compute normals = pobj->CreatePhongNormals(); when running on a background thread.
There was document clone (via GetClone), then started a background thread, then called doc_clone->ExecutePasses on the new thread. Then parsed the cloned doc and reached the call normals = pobj->CreatePhongNormals(); And this call for normals calculations crashes Cinema if the object has more than 8192 polygons (the number is something like that). E.g. create a sphere with 128 segments and it will crash. If there are say 120 segments on the sphere it doesn't crash. 
If I comment the line with "normals = pobj->CreatePhongNormals();" then there is no crash. And e.g. there is also no crash on R17 for the same code. Without this background thread (running on Main thread) everything is fine on R18 too.

It seems like there is no enogh memory inside CreatePhongNormals for objects with more than ~8K polygons. How to fix that?
I can also add that the background thead where these thing is running is std::thread. Haven't yet tried with C4DThread. Does that make any sense?

Please help me to fix the issue.

Thanks,
Aaron
Back to Top
S_Bach View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2011 Jun 27
Online Status: Offline
Posts: 1330
Post Options Post Options   Quote S_Bach Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 26 at 1:39am
Hello,

we advise to use C4DThread instead of std::thread. Does the issue also occur using C4DThread and under R19? You find information on C4DThread in the C4DThread Manual.

Using C4DThread and R19 I could not reproduce any issue with CreatePhongNormals(). This is the code I used:


class PhongThread : public C4DThread
{
public:

  BaseDocument* _copy = nullptr;

  void SetDoc(BaseDocument* orignal)
  {
    if (_copy)
      BaseDocument::Free(_copy);

    if (orignal)
    {
      C4DAtom* copy = orignal->GetClone(COPYFLAGS_0, nullptr);
      _copy = static_cast<BaseDocument*>(copy);
    }
  }

  void Main()
  {
    if (_copy)
    {
      _copy->ExecutePasses(this->Get(), true, true, true, BUILDFLAGS_EXTERNALRENDERER);

      BaseObject* object = _copy->GetFirstObject();
      if (object && object->IsInstanceOf(Opolygon))
      {
        PolygonObject* poly = ToPoly(object);
        if (poly)
        {
          Vector32* normals = poly->CreatePhongNormals();
          DeleteMem(normals);
        }
      }
      BaseDocument::Free(_copy);
    }
  }

  const Char* GetThreadName()
  {
    return "PhongThread";
  }
};


Does this code reproduce the issue for you? If not, could you post some code to reproduce the issue?

best wishes,
Sebastian

Edited by S_Bach - 2017 Sep 26 at 1:40am
SDK Support Engineer
Back to Top
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 26 at 3:09am
Hi Sebastian,
I will test it now on R18. Thanks for the sample. It seems that there is something (probably) with per-thread allocator. Strange thing is that ExecutePasses (which is more complex with caches builder) is working in such a std::thread and a simpler thing like CreatePhongNormals not. Will test C4DThread and minimize the code using std::thread for your diagnostics. Btw R18 was R18.11 then updaed to R18.57 and result was the same crash.
Don't yet have R19, can't test on it.
Back to Top
Aaron94 View Drop Down
Member
Member


Joined: 2015 Dec 15
Online Status: Offline
Posts: 78
Post Options Post Options   Quote Aaron94 Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 26 at 5:51am
With direct replacement from std::thread to C4DThread it works without problems now!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.