From a606b03fd749a204959e4de97441dbc4c6d65b6e Mon Sep 17 00:00:00 2001 From: bitsawer Date: Thu, 17 Aug 2023 11:17:54 +0300 Subject: [PATCH] Fix Shader and ShaderInclude resource loading (cherry picked from commit 26e3443eef49a7189eba5e1648ae7be13d95afd2) --- scene/resources/shader.cpp | 13 ++++++++----- scene/resources/shader_include.cpp | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 361a28194fc..ac6bffa077f 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -234,13 +234,16 @@ Ref ResourceFormatLoaderShader::load(const String &p_path, const Strin *r_error = ERR_FILE_CANT_OPEN; } - Ref shader; - shader.instantiate(); - - Vector buffer = FileAccess::get_file_as_bytes(p_path); + Error error = OK; + Vector buffer = FileAccess::get_file_as_bytes(p_path, &error); + ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader: " + p_path); String str; - str.parse_utf8((const char *)buffer.ptr(), buffer.size()); + error = str.parse_utf8((const char *)buffer.ptr(), buffer.size()); + ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot parse shader: " + p_path); + + Ref shader; + shader.instantiate(); shader->set_include_path(p_path); shader->set_code(str); diff --git a/scene/resources/shader_include.cpp b/scene/resources/shader_include.cpp index 6e9c64d34b4..f4bbb44fd1d 100644 --- a/scene/resources/shader_include.cpp +++ b/scene/resources/shader_include.cpp @@ -88,13 +88,16 @@ Ref ResourceFormatLoaderShaderInclude::load(const String &p_path, cons *r_error = ERR_FILE_CANT_OPEN; } - Ref shader_inc; - shader_inc.instantiate(); - - Vector buffer = FileAccess::get_file_as_bytes(p_path); + Error error = OK; + Vector buffer = FileAccess::get_file_as_bytes(p_path, &error); + ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader include: " + p_path); String str; - str.parse_utf8((const char *)buffer.ptr(), buffer.size()); + error = str.parse_utf8((const char *)buffer.ptr(), buffer.size()); + ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot parse shader include: " + p_path); + + Ref shader_inc; + shader_inc.instantiate(); shader_inc->set_include_path(p_path); shader_inc->set_code(str);