Godot Version
4.3
Question
I am making a project in which, when loading icons for elements to use they get them from a dictionary which is filled with everything from inside an Icons folder when the programme is launched, so they all get to share / reference the same resource(s).
This works great in the editor / debug releases, but when trying to load them in exported non-debug builds it fails.
The code (which is called for every icon):
func load_svg_to_img(svg_path : String, scale : float = 1.0) -> ImageTexture:
var bitmap : Image = Image.new()
print("trying to load svg from path: " + svg_path)
print("does this path exist? " + str(FileAccess.file_exists(svg_path))
print("is this file empty? " + str(len(FileAccess.open(svg_path, FileAccess.READ).get_as_text()) == 0))
bitmap.load_svg_from_buffer(FileAccess.get_file_as_bytes(svg_path), scale)
var texture : ImageTexture = ImageTexture.create_from_image(bitmap)
texture.resource_name = svg_path.get_file().replace(".svg", "").replace(".import", "")
#I name these resources to make checking icons easier in other bits of code
return ImageTexture.create_from_image(bitmap)
And when running with the console (since the console if left from exporting in debug previously and then you re-export a release version the console will still run the release version) I am getting this output:
trying to load svg from path: res://Assets/Icons/icon.svg.import
does this path exist? true
is this file empty? falseERROR: ImageLoaderSVG: Failed to create SVG buffer, error code 30.
at: (modules/svg/image_loader_svg.cpp:75)ERROR: Condition “!image.is_valid()” is true. Returning ERR_PARSE_ERROR
at: load_svg_from_buffer (core/io/image.cpp:3862)below printed twice before it crashed
ERROR: Invalid image: image is empty
at (scene/resources/image_texture.cpp:77)
I have looked at both the image.cpp and image_loader_svg.cpp at the given lines from the Godot github but one line was seemingly empty and the other I didn’t understand as I don’t know C++
Can one of you please explain what the problem is here? Especially since this works in editor / debug version and it is just the release version where it breaks is really confusing me.
Thanks.