From 6a3fa76e00f01551a3f03e317f74c62413a6b9ad Mon Sep 17 00:00:00 2001 From: ZioPao Date: Wed, 2 Apr 2025 18:12:45 +0200 Subject: [PATCH] Fix: added more checks in DataController to prevent issues, thanks PhysiksTV --- .vscode/settings.json | 6 +++++- .../lua/client/TOC/Controllers/DataController.lua | 14 +++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9cada6f..a95b2c5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,5 +16,9 @@ "Lua.format.defaultConfig": { "indent_style": "space", "indent_size": "2" - } + }, + "Lua.workspace.library": [ + "C:\\Users\\picch\\Zomboid\\Umbrella", + "C:\\Users\\picch\\Zomboid\\mods\\The-Only-Cure" + ], } \ No newline at end of file diff --git a/common/media/lua/client/TOC/Controllers/DataController.lua b/common/media/lua/client/TOC/Controllers/DataController.lua index 7dde5bd..65b621c 100644 --- a/common/media/lua/client/TOC/Controllers/DataController.lua +++ b/common/media/lua/client/TOC/Controllers/DataController.lua @@ -5,7 +5,7 @@ local StaticData = require("TOC/StaticData") ---------------- --- An instance will be abbreviated with dcInst - +-- https://github.com/ZioPao/The-Only-Cure/issues/187 --- Handle all TOC mod data related stuff ---@class DataController @@ -103,6 +103,10 @@ end ---In case of desync between the table on ModData and the table here ---@param tocData tocModDataType function DataController:applyOnlineData(tocData) + if not tocData or not tocData.limbs then + TOC_DEBUG.print("Received invalid tocData") + return + end local key = CommandsData.GetKey(self.username) ModData.add(key, tocData) self.tocData = ModData.get(key) @@ -229,12 +233,8 @@ end ---@param limbName string ---@return boolean function DataController:getIsCut(limbName) - if not self.isDataReady then return false end - if self.tocData.limbs[limbName] then - return self.tocData.limbs[limbName].isCut - else - return false - end + if not self.isDataReady or not self.tocData or not self.tocData.limbs then return false end + return self.tocData.limbs[limbName] and self.tocData.limbs[limbName].isCut or false end ---Get isVisible