Skip to content

Commit 773ec03

Browse files
(Fix) Prevent duplicate custom model loads causing early load before download complete (PR #72 by denjifb)
2 parents ae76e35 + 434577f commit 773ec03

2 files changed

Lines changed: 23 additions & 5 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,

newmodels_red/scripts/optional/debug/c_debug.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ end
3535

3636
local function updateDebugViewInfo()
3737
local loadedModelsStr_ = ""
38+
local count = 0
3839
for customModel, v in pairsByKeys(loadedModels) do
3940
local str = ("%d \"%s\" (%d)"):format(customModel, v.name, v.baseModel)
4041
if loadedModelsStr_ == "" then
4142
loadedModelsStr_ = str
4243
else
4344
loadedModelsStr_ = str .. ", " .. loadedModelsStr_
4445
end
46+
count = count + 1
4547
end
4648
if loadedModelsStr_ ~= "" then
47-
loadedModelsStr = "Loaded new models (client-side):\n" .. loadedModelsStr_
49+
loadedModelsStr = ("Loaded new models (client-side: %d):\n"):format(count) .. loadedModelsStr_
4850
else
4951
loadedModelsStr = "No new models loaded (client-side)"
5052
end

0 commit comments

Comments
 (0)