Need Help Debugging EXC_BAD_ACCESS error during render
-
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.
Thanks for any help! -
Well, what are your settings?
What is
doc
? Is it the active document or a clone? Did you setNODOCUMENTCLONE
or not?You find an example of using
RenderDocument()
in a thread here C4DThread Manual. -
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? -
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 letRenderDocument
clone it by omitting the flagNODOCUMENTCLONE
. 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 -
@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.
-
@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 aSpecialEventAdd(CUSTOMEVENT::)
message and when I caught that message I was callingEventAdd()
which you can only do from the main thread I think. -
@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!
-
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