From 70175a8af00133c7dcd9c0e8c0fc084eb5fd158d Mon Sep 17 00:00:00 2001 From: Christophe Date: Wed, 27 Nov 2024 13:16:20 +0100 Subject: [PATCH] vkconfig3: Fix crash of layers with unknowned preset value Change-Id: I3481cd9e5e046eea1b885fc456c7c43000e3117d --- vkconfig_core/layer.cpp | 3 ++ .../test/layers/VK_LAYER_LUNARG_test_07.json | 39 +++++++++++++++++++ vkconfig_core/test/resources.qrc | 1 + vkconfig_core/test/test_layer.cpp | 12 ++++++ 4 files changed, 55 insertions(+) create mode 100644 vkconfig_core/test/layers/VK_LAYER_LUNARG_test_07.json diff --git a/vkconfig_core/layer.cpp b/vkconfig_core/layer.cpp index d1ad15d6f4..6733454a32 100644 --- a/vkconfig_core/layer.cpp +++ b/vkconfig_core/layer.cpp @@ -468,6 +468,9 @@ void Layer::AddSettingData(SettingDataSet& settings_data, const QJsonValue& json const std::string& key = ReadStringValue(json_setting_object, "key"); SettingMeta* setting_meta = FindSetting(this->settings, key.c_str()); + if (setting_meta == nullptr) { + return; + } assert(setting_meta); SettingData* setting_data = setting_meta->Instantiate(); diff --git a/vkconfig_core/test/layers/VK_LAYER_LUNARG_test_07.json b/vkconfig_core/test/layers/VK_LAYER_LUNARG_test_07.json new file mode 100644 index 0000000000..3ba0126d80 --- /dev/null +++ b/vkconfig_core/test/layers/VK_LAYER_LUNARG_test_07.json @@ -0,0 +1,39 @@ +{ + "file_format_version": "1.2.0", + "layer": { + "name": "VK_LAYER_LUNARG_test_07", + "library_path": ".\\VkLayer_test.dll", + "api_version": "1.2.170", + "implementation_version": "Build 76", + "description": "Missing setting", + "platforms": [ "WINDOWS", "LINUX" ], + "status": "BETA", + "features": { + "presets": [ + { + "label": "Preset Inherit", + "description": "Description Inherit", + "settings": [ + { + "key": "int_required_only", + "value": 75 + }, + { + "key": "int_missing", + "value": 76 + } + ] + } + ], + "settings": [ + { + "key": "int_required_only", + "type": "INT", + "label": "Integer", + "description": "Integer Description", + "default": 82 + } + ] + } + } +} diff --git a/vkconfig_core/test/resources.qrc b/vkconfig_core/test/resources.qrc index ccdf627cea..4fee9d98c8 100644 --- a/vkconfig_core/test/resources.qrc +++ b/vkconfig_core/test/resources.qrc @@ -34,6 +34,7 @@ ./layers/VK_LAYER_LUNARG_test_04.json ./layers/VK_LAYER_LUNARG_test_05.json ./layers/VK_LAYER_LUNARG_test_06.json + ./layers/VK_LAYER_LUNARG_test_07.json ./layers/VK_LAYER_LUNARG_version_135.json ./layers/VK_LAYER_LUNARG_version_193.json diff --git a/vkconfig_core/test/test_layer.cpp b/vkconfig_core/test/test_layer.cpp index 0f1429e8cc..47d6eef733 100644 --- a/vkconfig_core/test/test_layer.cpp +++ b/vkconfig_core/test/test_layer.cpp @@ -213,6 +213,18 @@ TEST(test_layer, load_setting_enum_interit) { EXPECT_EQ(SETTING_VIEW_HIDDEN, setting_override->enum_values[1].view); } +TEST(test_layer, load_setting_missing) { + Layer layer; + const LayerLoadStatus load_loaded = layer.Load(":/layers/VK_LAYER_LUNARG_test_07.json", LAYER_TYPE_EXPLICIT, false, Dummy()); + EXPECT_EQ(load_loaded, LAYER_LOAD_ADDED); + + EXPECT_EQ(Version(1, 2, 0), layer.file_format_version); + EXPECT_EQ(PLATFORM_WINDOWS_BIT | PLATFORM_LINUX_BIT, layer.platforms); + EXPECT_EQ(STATUS_BETA, layer.status); + EXPECT_EQ(1, layer.settings.size()); + EXPECT_EQ(1, layer.presets.size()); +} + TEST(test_layer, load_1_1_0_header) { Layer layer; const LayerLoadStatus load_loaded =