Skip to content

Commit 93ddf54

Browse files
authored
fix: prevent duplicate custom model loads causing early load before download complete
1 parent 0a334c0 commit 93ddf54

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

newmodels_red/scripts/core/client_logic.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ local function finishLoadCustomModel(customModel)
7070

7171
local allocatedModel = queuedInfo.allocatedModel
7272
local col, txd, dff = queuedInfo.col, queuedInfo.txd, queuedInfo.dff
73-
local elementToApply = queuedInfo.elementToApply
73+
local waitingElements = queuedInfo.waitingElements or {}
7474

7575
local function cancelLoading()
7676
-- Destroy all non-reused col/txd/dff elements
@@ -146,8 +146,11 @@ local function finishLoadCustomModel(customModel)
146146
},
147147
disableAutoFree = disableAutoFree or false,
148148
}
149-
if isElement(elementToApply) then
150-
applyElementCustomModel(elementToApply)
149+
150+
for element, _ in pairs(waitingElements) do
151+
if isElement(element) then
152+
applyElementCustomModel(element)
153+
end
151154
end
152155

153156
loadingQueue[customModel] = nil
@@ -388,6 +391,14 @@ local function beginDownloadModelFiles(customModel)
388391
end
389392

390393
local function beginLoadCustomModel(customModel, elementToApply)
394+
if loadingQueue[customModel] then
395+
-- Model is already loading, add this element to the waiting list
396+
if isElement(elementToApply) then
397+
loadingQueue[customModel].waitingElements[elementToApply] = true
398+
end
399+
return
400+
end
401+
391402
local customInfo = customModels[customModel]
392403
if not customInfo then
393404
outputDebugString("Trying to load custom model " .. customModel .. " that does not exist", 2)
@@ -406,8 +417,13 @@ local function beginLoadCustomModel(customModel, elementToApply)
406417
if txdPath then filesList[#filesList + 1] = { type = "txd", path = txdPath } end
407418
if dffPath then filesList[#filesList + 1] = { type = "dff", path = dffPath } end
408419

420+
local waitingElements = {}
421+
if isElement(elementToApply) then
422+
waitingElements[elementToApply] = true
423+
end
424+
409425
loadingQueue[customModel] = {
410-
elementToApply = elementToApply,
426+
waitingElements = waitingElements,
411427
filesList = filesList,
412428
-- Start in Phase 1
413429
phase = LOADING_QUEUE_PHASES.DOWNLOAD_FILES,

0 commit comments

Comments
 (0)