From 66a3a944e24e341658b5a48920ec8c0e9c31e5c5 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Fri, 12 Apr 2024 18:01:58 +0800 Subject: [PATCH] Fix error when loading SVG imported as Image --- modules/svg/image_loader_svg.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index affe163aeb2..d9031371956 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -173,9 +173,17 @@ void ImageLoaderSVG::get_recognized_extensions(List *p_extensions) const } Error ImageLoaderSVG::load_image(Ref p_image, Ref p_fileaccess, BitField 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 buffer; + buffer.resize(len); + p_fileaccess->get_buffer(buffer.ptrw(), buffer.size()); + + String svg; + Error err = svg.parse_utf8((const char *)buffer.ptr(), buffer.size()); + if (err != OK) { + return err; + } - Error err; if (p_flags & FLAG_CONVERT_COLORS) { err = create_image_from_string(p_image, svg, p_scale, false, forced_color_map); } else {