Skip to content

Commit

Permalink
Merge pull request #2053 from alicevision/mug/scenePreviewClearImages
Browse files Browse the repository at this point in the history
[blender] preview: clear loaded images to avoid memory leak
  • Loading branch information
fabiencastan committed Jun 13, 2023
2 parents 44da5db + 9449199 commit 0c137a1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions meshroom/nodes/blender/scripts/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ def setupBackground(view, folderUndistorted):
matches = glob.glob(folderUndistorted + '/*' + baseImgName + "*") # try with image name
if len(matches) == 0:
# no background image found
return False
return None
undistortedImgPath = matches[0]
bpy.ops.image.open(filepath=undistortedImgPath)
undistortedImgName = os.path.basename(undistortedImgPath)
bpy.context.scene.node_tree.nodes["Image"].image = bpy.data.images[undistortedImgName]
return True
img = bpy.data.images.load(filepath=undistortedImgPath)
bpy.context.scene.node_tree.nodes["Image"].image = img
return img


def loadModel(filename):
Expand Down Expand Up @@ -335,14 +334,20 @@ def main():
continue

print("Rendering view " + view['viewId'])
img = None
if args.useBackground:
if not setupBackground(view, args.undistortedImages):
img = setupBackground(view, args.undistortedImages)
if not img:
# background setup failed
# do not render this frame
continue
setupRender(view, intrinsic, pose, args.output)
bpy.ops.render.render(write_still=True)

if img:
# clear memory
bpy.data.images.remove(img)

print("Done")
return 0

Expand Down

0 comments on commit 0c137a1

Please sign in to comment.