Skip to content

Commit

Permalink
blender: Fix bug where c-ray was never deleted
Browse files Browse the repository at this point in the history
Turns out, I was passing self into the callback args, which presumably
then held a reference to it, which meant that the Blender python runtime
never calls __del__() on it. I wasn't even using self for anything, I
was just grabbing the current sample count from it.
Fix is to just pass in the sample count directly, instead of passing in
self.
  • Loading branch information
vkoskiv committed Oct 31, 2024
1 parent 78a3aad commit 94269a7
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions bindings/blender_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def draw_direct(bitmap):
draw_texture_2d(texture, (0, 0), texture.width, texture.height)

def status_update_interactive(cb_info, args):
tag_redraw, update_stats, self = args
tag_redraw, update_stats, total_samples = args;
tag_redraw()
if cb_info.finished_passes == self.cr_renderer.prefs.samples:
if cb_info.finished_passes == total_samples:
update_stats("Rendering done", "")
else:
update_stats("Sample {}".format(cb_info.finished_passes), "")
Expand All @@ -193,8 +193,6 @@ def __init__(self):
c_ray.log_level_set(c_ray.log_level.Debug)

def __del__(self):
# FIXME: This never gets called when leaving rendered viewport shading mode
# which ends up leaving zombie instances of c-ray running in the background
if self.cr_renderer:
if self.cr_renderer.interactive:
self.cr_renderer.stop()
Expand Down Expand Up @@ -481,7 +479,7 @@ def view_update(self, context, depsgraph):
sync_end = time.time()
print("Sync took {}s".format(sync_end - sync_start))
print("Kicking off background renderer")
self.cr_renderer.callbacks.on_interactive_pass_finished = (status_update_interactive, (self.tag_redraw, self.update_stats, self))
self.cr_renderer.callbacks.on_interactive_pass_finished = (status_update_interactive, (self.tag_redraw, self.update_stats, self.cr_renderer.prefs.samples))
self.cr_renderer.start_interactive()

def display_bitmap(self, bm):
Expand Down

0 comments on commit 94269a7

Please sign in to comment.