From 574e61a542ea336902613d8c7b658e38b351ddae Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Mon, 22 Jul 2024 19:17:03 +0300 Subject: [PATCH] Fix crash when assigning more textures than expected to texture array --- drivers/gles3/storage/material_storage.cpp | 3 ++- servers/rendering/renderer_rd/storage_rd/material_storage.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 1aaf840b306f..41c23fc3ec03 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -874,7 +874,8 @@ void MaterialData::update_textures(const HashMap &p_paramet if (V->value.is_array()) { Array array = (Array)V->value; if (uniform_array_size > 0) { - for (int j = 0; j < array.size(); j++) { + int size = MIN(uniform_array_size, array.size()); + for (int j = 0; j < size; j++) { textures.push_back(array[j]); } } else { diff --git a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp index 13b00be1c434..8b74ebfacd15 100644 --- a/servers/rendering/renderer_rd/storage_rd/material_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/material_storage.cpp @@ -807,7 +807,8 @@ void MaterialStorage::MaterialData::update_textures(const HashMapvalue.is_array()) { Array array = (Array)V->value; if (uniform_array_size > 0) { - for (int j = 0; j < array.size(); j++) { + int size = MIN(uniform_array_size, array.size()); + for (int j = 0; j < size; j++) { textures.push_back(array[j]); } } else {