Hi! I’m new to Blender addons. I’m writing an addon that involves the action of downloading an image and then loading the image as an environment and background. However, I do not want to keep the downloaded image on the disk, so I would like to delete the image from the disk after loading as a texture.
Here’s what my code looks like
bg_node = my_node_tree.nodes.new('ShaderNodeBackground')
env_node = my_node_tree.nodes.new('ShaderNodeTexEnvironment')
output_node = my_node_tree.nodes.new('ShaderNodeOutputWorld')
image = bpy.data.images.load(tmp_file_name, check_existing=True)
env_node.image = image
my_node_tree.links.new(env_node.outputs['Color'], bg_node.inputs['Color'])
my_node_tree.links.new(bg_node.outputs['Background'], output_node.inputs['Surface'])
# time.sleep(10)
os.remove(tmp_file_name)
The problem I’m facing right now is that the image file was deleted before the image loading was completed. Running this code above would give me a pink background, with an error message GPUTexture: Blender Texture Not Loaded!
. From what I understand, pink background = the image being loading is moved, renamed, or even corrupted(in my case, deleted before loading completed). Also, if I put a long sleep(as the 10s sleep in the comment above), or if I do not remove the file at the end, both would give me the correct result(downloaded image as the background instead of the pink background).
So is there a reliable way to tell if the loading is completed so that I can delete the file?
Thanks!