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

Fix error when loading SVG imported as Image #90573

Merged
merged 1 commit into from
Apr 14, 2024

Conversation

timothyqiu
Copy link
Member

If an SVG file is imported as Image, trying to open it in the editor produces these error:

core/io/file_access.cpp:504 - Condition "r != len" is true. Returning: String()
Failed loading resource: res://.godot/imported/new.svg-43c58458c66d384f2ca7a4ce4dd3ac63.image. Make sure resources have been imported by opening the project in the editor at least once.
Failed loading resource: res://new.svg. Make sure resources have been imported by opening the project in the editor at least once.
editor/editor_node.cpp:1225 - Condition "!res.is_valid()" is true. Returning: ERR_CANT_OPEN

It's because get_as_utf8_string() is used to load SVG string. This method expects a brand new FileAccess, however for an Image, a header is already stripped from file content. So this PR reads the rest of the file manually.

@timothyqiu timothyqiu requested a review from a team as a code owner April 12, 2024 10:10
@akien-mga akien-mga added bug topic:import cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release labels Apr 12, 2024
@akien-mga akien-mga added this to the 4.3 milestone Apr 12, 2024
@@ -173,9 +173,17 @@ void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const
}

Error ImageLoaderSVG::load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) {
String svg = p_fileaccess->get_as_utf8_string();
const uint64_t len = p_fileaccess->get_length() - p_fileaccess->get_position();
Vector<uint8_t> buffer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to have length < -1 or >= p_fileaccess->get_length(), so we don't need a err index check but..

Copy link
Member

@fire fire Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However it is missing is_null checks on the inputs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which input do you mean? Null checks for p_image and p_fileaccess are done at ImageLoader::load_image() level.

@akien-mga akien-mga merged commit 122054c into godotengine:master Apr 14, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@timothyqiu timothyqiu deleted the svg-image branch April 14, 2024 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release topic:import
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants