From e7dc58c596941c56193acc4e4bbe534d773625f7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Sep 2024 09:11:55 +0200 Subject: [PATCH] Fix crash when showing shader source that is empty #2896 --- Source/Editor/Managed/ManagedEditor.Internal.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Managed/ManagedEditor.Internal.cpp b/Source/Editor/Managed/ManagedEditor.Internal.cpp index 31295253f..d8ea556c8 100644 --- a/Source/Editor/Managed/ManagedEditor.Internal.cpp +++ b/Source/Editor/Managed/ManagedEditor.Internal.cpp @@ -272,11 +272,13 @@ DEFINE_INTERNAL_CALL(MString*) EditorInternal_GetShaderAssetSourceCode(BinaryAss obj->GetChunkData(SHADER_FILE_CHUNK_SOURCE, data); auto source = data.Get(); auto sourceLength = data.Length(); + if (sourceLength <= 0) + return MCore::String::GetEmpty(); Encryption::DecryptBytes(data.Get(), data.Length()); source[sourceLength - 1] = 0; // Get source and encrypt it back - const StringAnsiView srcData((const char*)data.Get(), data.Length()); + const StringAnsiView srcData(source, sourceLength); const auto str = MUtils::ToString(srcData); Encryption::EncryptBytes(data.Get(), data.Length());