Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[blender] preview: clear loaded images to avoid memory leak #2053

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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