Changes in Blender 3.0, 3.1 leading to a segfault when rendering using Crowdrender

Hi @brecht Just flagging an issue I’ve had when testing Cycles X in the new 3.0 beta and 3.1 builds which I downloaded today. I am testing the latest update to the Crowdrender addon that I am building, sadly when I render with our addon, it causes an access violation in windows.

Curiously enough this doesn’t happen on MacOS, only on the windows build, and I haven’t yet tested linux.

The problem is related to the desire to render on the local machine, where the user’s session of Blender is running. Being able to render on the same machine as the user is working on makes our addon useful for distributed rendering (or network rendering if you prefer that term) where the user only has two computers and wants use them both to render.

In order to render on the local machine, a copy of the Blend file that is currently open in blender needs to be saved so it can be rendered in background and the results later ingested back into blender, along with the result from the other machine/machines.

This is where the access violation is happening. The moment I call bpy.ops.wm.save_as_copy or save_mainfile, Blender crashes. I am assuming this is due to changes in the render engine API or related code post integration of cycles X as I don’t recall this being an issue prior to that happening. The issue also isn’t present in the current official LTS releases of 2.93.

So I have done some thinking and thought I need to reach out to the Blender devs to find a proper solution. I have a couple of questions

  1. What is the best way to render locally? Or perhaps, am I doing something that is fundamentally flawed? So far I have looked at;

    • Streaming data out to another process, other render engines do this, but then I’d need to know how to stream it into a background process of Blender, which seems a bit daunting.

    • Keeping a background process open and updating it with our synchronisation code, wastes resources in my mind since a whole extra scene would be loaded in background just to keep things up to date in case the user wanted to render.

    • Invoking cycles standalone from within the user’s session, looks hard, not sure how to approach this as it appears that cycles and blender are interrelated, so not sure how to do this.

  2. If the current way I am doing it is the best way (or least worse way) is there any chance of this crash being fixed? I am more than happy to write up an issue for this on developer.blender.org

Thanks in advance :slight_smile:
James

If bpy.ops.wm.save_as_copy or save_mainfile crashes, that sounds like a bug in Blender that can be reported to the tracker. Cycles is not involved in file saving so it’s not obvious how it could cause this, though there may be some indirect interaction.

Saving a copy of the .blend file seems like the proper solution to me, I think it’s just a bug to be fixed.

1 Like

Hi @brecht ok, great! I’ll be writing up a bug for the tracker asap. I’ll post a link here when that’s done too.

Thanks again for your help :slight_smile:

Hey, since this is a bug report, and not a development topic, I’m moving this to be unlisted.

Hi, does this mean the post is still reachable at the same URL? We might direct a few ppl here who ask why our addon crashes Blender. At least until the bug report is done anyway.

Opened it in private mode and it’s readable, so yeah.

1 Like

Thanks for confirming!

Hi @brecht, @dfelinto there is now a bug report for this issue, which can be found here.

Hi @brecht, any idea who the module owner for the window manager C code is? That’s where the crash is happening. Seems to be that the wm_file_write method in wm_files.c forces a redraw of the interface and this is where the crash happens.

Crash is also both on mac and windows now (linux remains to be tested). Would like to talk and assist with the solution :slight_smile: always keen to learn more Blender code and help improve where I can. If nothing else I can test and do more diagnosis at my end.

Thanks!

@brecht Hey mate, know you’re busy, would appreciate it if you can point me at the right module owner for this issue :smiley:

In case you haven’t seen it. I’ve coded a solution that works for me, would like to offer it as a patch. Long story short, there was a change to the wm_file_write code back in September that causes the UI to be redrawn from the routine that saves the file.

I propose moving the redraw call to the invoke methods of the operators that are used to save the file, not the exec method. I tested this in my own branch and save still works, same as it does prior to the change as far as I can tell, and there are no more crashes when our addon attempts to render.

I’d like to offer this change as a patch, this is my first one too by the way, so appreciate any advice on how to do this properly :slight_smile:

Hi, this should have all of the information you need: Process/Contributing Code - Blender Developer Wiki

If not, reach out to #blender-coders on blender.chat, someone will be available to point you in the right direction.

1 Like

Thanks @HooglyBoogly, appreciate you pointing me in the right direction :slight_smile:

With huge thanks to @HooglyBoogly, @brecht and @ideasman42… I think I just contributed a patch to Blender?!

afc60f995701: Redrawing while saving crashes outside the main thread closes the issue I was having with rendering in Blender 3.0 beat and 3.1 alpha causing a crash.

Was a pretty neat experience never having contributed before. Wouldn’t mind doing that again actually :slight_smile: