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

    Need Help Debugging EXC_BAD_ACCESS error during render

    Cinema 4D SDK
    r21 macos c++
    4
    8
    848
    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.
    • J
      JuicyJuggles
      last edited by JuicyJuggles

      Hey There,

      I am using a plugin to launch a render on a separate thread. In my threads main function I use this to start the render:
      const RENDERRESULT res = RenderDocument(doc, renderSettings, progHook, nullptr, bitmap, renderFlags, nullptr);

      A handfuls of seconds after the render starts I am left with an EXC_BAD_ACCESS error. I think this means I am accessing something in memory I shouldn't but I don't know how to debug which thread or which variable is causing me issues.

      I have attached a screenshot of my error.
      Exec Error.jpg
      Thanks for any help!

      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by

        Well, what are your settings?

        What is doc? Is it the active document or a clone? Did you set NODOCUMENTCLONE or not?

        You find an example of using RenderDocument() in a thread here C4DThread Manual.

        1 Reply Last reply Reply Quote 1
        • J
          JuicyJuggles
          last edited by JuicyJuggles

          Hi thanks for your help.

          I did use NODOCUMENTCLONE. doc is the current open and active document.

          I setup the render like so:

          	RenderData* const rdata = doc->GetActiveRenderData();
          
          	BaseContainer renderSettings = rdata->GetData();
          	// render one frame
          	const BaseTime startFrame = renderSettings.GetTime(RDATA_FRAMEFROM, BaseTime());
          	renderSettings.SetTime(RDATA_FRAMETO, startFrame);
          	// target bitmap
          	AutoAlloc<BaseBitmap> bitmap;
          
          	const Int32       width = renderSettings.GetInt32(RDATA_XRES);
          	const Int32       height = renderSettings.GetInt32(RDATA_YRES);
          	const IMAGERESULT imageRes = bitmap->Init(width, height);
          
          	// render the image
          	const RENDERFLAGS  renderFlags = RENDERFLAGS::NODOCUMENTCLONE;
          	const RENDERRESULT res = RenderDocument(doc, renderSettings, progHook, nullptr, bitmap, renderFlags, nullptr);
          

          I might just copy that example you showed as that is very similar to what I need to do. Maybe you could also help explain the example: I don't get where g_displayBitmap is initialized. Is it a global variable?

          P 1 Reply Last reply Reply Quote 0
          • ferdinandF
            ferdinand
            last edited by ferdinand

            Hi,

            you have to either pass a document to RenderDocument that is not an active document (by either instantiating it yourself or by cloning it yourself) or let RenderDocument clone it by omitting the flag NODOCUMENTCLONE. Your error is most likely caused by both the render process and the editor trying to take control over the document at the same time.

            Cheers,
            zipit

            MAXON SDK Specialist
            developers.maxon.net

            J 1 Reply Last reply Reply Quote 1
            • P
              PluginStudent @JuicyJuggles
              last edited by

              @JuicyJuggles said in Need Help Debugging EXC_BAD_ACCESS error during render:

              I don't get where g_displayBitmap is initialized. Is it a global variable?

              Yes, its a global variable. See Code Style Guide.

              J 1 Reply Last reply Reply Quote 0
              • J
                JuicyJuggles @ferdinand
                last edited by

                @zipit Thank you for your comment! The render thread was trying to take the document from the main thread and that was the first part of my issue. I also had a progressHook callback that was sending a SpecialEventAdd(CUSTOMEVENT::) message and when I caught that message I was calling EventAdd() which you can only do from the main thread I think.

                1 Reply Last reply Reply Quote 0
                • J
                  JuicyJuggles @PluginStudent
                  last edited by

                  @PluginStudent Thank you for pointing me at the specific examples in the docs. It can be a little daunting finding the right thing. I was able to solve my problem using your example as a template.

                  Thanks!

                  1 Reply Last reply Reply Quote 0
                  • r_giganteR
                    r_gigante
                    last edited by r_gigante

                    Hi @JuicyJuggles , I apologize for coming late here but luckly you've been already provided in the meanwhile of some good guidance from @PluginStudent and @zipit .

                    Rest assured that the API documentation is, by far, the best place where to look for answers although I can see that, due to huge number of covered topics, it could take time to get used to browse it effectively.

                    Last but not least, if the issue is addressed, don't forget to mark the right post as correct answer or if it's not possible to identify a specific one, to set the whole topic as Solved

                    Cheers, Riccardo

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