From b566e6ea96ab308479540f8645530e0efe6acda5 Mon Sep 17 00:00:00 2001 From: Manuel Pietschmann Date: Tue, 26 Nov 2024 12:08:59 +0100 Subject: [PATCH] Fix ResourceItems no longer handled when additional DDFs are loaded (#8043) Problem in the issue was reproduced by joining a device without DDF, existing devices stopped processing some of the resource items. The main issue was that when loading new DDFs during a session the load counter got updated for all items in all DDFs, but the device items in memory still pointed to former load counter. TLTR the load counter should only be incremented for the actually new DDF which is loaded into memory. https://github.com/dresden-elektronik/deconz-rest-plugin/issues/7935 --- device_descriptions.cpp | 46 +---------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/device_descriptions.cpp b/device_descriptions.cpp index 64f43dc47c..8cffa053b8 100644 --- a/device_descriptions.cpp +++ b/device_descriptions.cpp @@ -163,7 +163,6 @@ static int DDF_MergeGenericBundleItems(DeviceDescription &ddf, DDF_ParseContext static int DDF_ProcessSignatures(DDF_ParseContext *pctx, std::vector &publicKeys, U_BStream *bs, uint32_t *bundleHash); static DeviceDescription::Item *DDF_GetItemMutable(const ResourceItem *item); static void DDF_UpdateItemHandlesForIndex(std::vector &descriptions, uint loadCounter, size_t index); -static void DDF_UpdateItemHandles(std::vector &descriptions, uint loadCounter); static void DDF_TryCompileAndFixJavascript(QString *expr, const QString &path); DeviceDescription DDF_LoadScripts(const DeviceDescription &ddf); @@ -1871,48 +1870,6 @@ static void DDF_UpdateItemHandlesForIndex(std::vector &descri } } -/*! Updates all DDF item handles to point to correct location. - \p loadCounter - the current load counter. - */ -static void DDF_UpdateItemHandles(std::vector &descriptions, uint loadCounter) -{ - for (size_t index = 0; index < descriptions.size(); index++) - { - DDF_UpdateItemHandlesForIndex(descriptions, loadCounter, index); - } - - // int index = 0; - // U_ASSERT(loadCounter >= HND_MIN_LOAD_COUNTER); - // U_ASSERT(loadCounter <= HND_MAX_LOAD_COUNTER); - - // ItemHandlePack handle; - // handle.description = 0; - // handle.loadCounter = loadCounter; - - // for (DeviceDescription &ddf : descriptions) - // { - // ddf.handle = index++; - // handle.subDevice = 0; - // for (auto &sub : ddf.subDevices) - // { - // handle.item = 0; - - // for (auto &item : sub.items) - // { - // item.handle = handle.handle; - // U_ASSERT(handle.item < HND_MAX_ITEMS); - // handle.item++; - // } - - // U_ASSERT(handle.subDevice < HND_MAX_SUB_DEVS); - // handle.subDevice++; - // } - - // U_ASSERT(handle.description < HND_MAX_DESCRIPTIONS); - // handle.description++; - // } -} - /*! Temporary workaround since DuktapeJS doesn't support 'let', try replace it with 'var'. The fix only applies if the JS doesn't compile and after the modified version successfully @@ -2343,6 +2300,7 @@ void DeviceDescriptions::readAllRawJson() DBG_Printf(DBG_DDF, "DDF cache raw JSON DDF %s\n", pctx->filePath); d->descriptions.push_back(std::move(result)); + DDF_UpdateItemHandlesForIndex(d->descriptions, d->loadCounter, d->descriptions.size() - 1); } } } @@ -2363,8 +2321,6 @@ void DeviceDescriptions::readAllRawJson() if (!d->descriptions.empty()) { - DDF_UpdateItemHandles(d->descriptions, d->loadCounter); - for (auto &ddf : d->descriptions) { ddf = DDF_MergeGenericItems(d->genericItems, ddf);