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
    • Register
    • Login

    Problem with DeleteObj() and maxon::PointerArray

    Cinema 4D SDK
    c++ macos sdk
    2
    3
    834
    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.
    • codysorgenfreyC
      codysorgenfrey
      last edited by

      I'm workinig on a c++ plugin in R18 on Mac with Xcode. When I create a new maxon::PointerArray<customtype> with NewObj() in GetVirtualObjects, everything is working great. The problem is when I go to free the pointer array with DeleteObj() after i'm done with it I get a EXC_BAD_ACCESS.

      My question is, how do I free up this array? Do I need too, or does the auto memory management take care of it when it falls out of scope? It is local in my GetVirtualObjects method.

      Thanks!

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

        Hello,

        can you share some code to show that you are actually doing? Are you allocating the array or the objects stored in the array? If the array is a local variable, you can simply create in on the stack.

        I haven't tried R18 (only have R20 currently available).

        A PointerArray takes ownership of the stored objects. So it should not be needed to delete the objects manually. The objects are freed when the array is freed or reset.

        You find an example (for R20) in the Arrays Manual.

        best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • codysorgenfreyC
          codysorgenfrey
          last edited by codysorgenfrey

          Ahhhh thanks! I couldn't find an Array Manual in the R18 documentation.

          I was going like this:

          maxon::PointerArray<MyCustomClass> myPointerArr = NewObj(maxon::PointerArray<MyCustomClass>);
          DoStuffWithArray(myPointerArr);
          DeleteObj(myPointerArr);
          

          It seems my problem was with the PointerArray taking ownership of my pointers, then deallocating them before I was done with them. Since it doesn't seem that R18 has maxon::UniqueRef objects I decided to go with a maxon::BaseArray<MyCustomClass*> instead.

          Thanks again for your help Sebastian!

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