From 3920b2db053ebc7e43f7567ff5a62f8308573b6d Mon Sep 17 00:00:00 2001 From: bitsawer Date: Mon, 4 Sep 2023 14:59:59 +0300 Subject: [PATCH] Fix empty shader resource loading (cherry picked from commit 15eec2450a1911292106e3e815022234bad2363c) --- scene/resources/shader.cpp | 6 ++++-- scene/resources/shader_include.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index ac6bffa077f..1a86bcfbf48 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -239,8 +239,10 @@ Ref ResourceFormatLoaderShader::load(const String &p_path, const Strin ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader: " + p_path); String str; - error = str.parse_utf8((const char *)buffer.ptr(), buffer.size()); - ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot parse shader: " + p_path); + if (buffer.size() > 0) { + 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(); diff --git a/scene/resources/shader_include.cpp b/scene/resources/shader_include.cpp index f4bbb44fd1d..8afa7f5b398 100644 --- a/scene/resources/shader_include.cpp +++ b/scene/resources/shader_include.cpp @@ -93,8 +93,10 @@ Ref ResourceFormatLoaderShaderInclude::load(const String &p_path, cons ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot load shader include: " + p_path); String str; - error = str.parse_utf8((const char *)buffer.ptr(), buffer.size()); - ERR_FAIL_COND_V_MSG(error, nullptr, "Cannot parse shader include: " + p_path); + if (buffer.size() > 0) { + 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();