Skip to content

Commit 0215f40

Browse files
committed
Restore lazy editor initialization - fixes SB.view nil errors
Removed upfront InitializeAllEditors() approach that was causing errors. The problem: 1. widget.lua calls: SB.view = View() 2. Inside View() constructor, InitializeRmlUi() is called 3. InitializeRmlUi() called InitializeAllEditors() 4. Editors are created, but SB.view hasn't been assigned yet 5. CollisionView, ObjectPropertyWindow try to access SB.view → nil error The fix: - Restore lazy initialization (create editors on-demand when clicked) - OpenEditor() now creates editors on first use - By then, SB.view has been assigned in widget.lua - No more nil access errors This matches the original Chili architecture where editors are created when users click buttons, not during View initialization. Fixes: "attempt to index field 'view' (a nil value)" in collision_window.lua:287
1 parent 5888f38 commit 0215f40

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

scen_edit/view/view.lua

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ function View:InitializeRmlUi()
6363
return
6464
end
6565

66-
-- Initialize ALL editors upfront from editorRegistry
67-
-- This generates RML during init so we catch errors early
68-
-- The field compat layer makes existing Chili editors work with RmlUi automatically
69-
self:InitializeAllEditors()
66+
-- Initialize SB.editors table for lazy creation
67+
if not SB.editors then
68+
SB.editors = {}
69+
end
7070

7171
-- Initialize tab system
7272
self.currentTab = "Objects"
@@ -79,29 +79,6 @@ function View:InitializeRmlUi()
7979
Log.Notice("RmlUi UI initialized successfully - editors use field compatibility layer")
8080
end
8181

82-
function View:InitializeAllEditors()
83-
-- Initialize SB.editors table if it doesn't exist
84-
if not SB.editors then
85-
SB.editors = {}
86-
end
87-
88-
-- Instantiate all editors from editorRegistry
89-
-- This calls their init() which calls Finalize() which generates RML
90-
-- Doing this upfront catches field errors early instead of when users click buttons
91-
Log.Notice("Initializing all editors from editorRegistry...")
92-
local count = 0
93-
for name, editorCfg in pairs(SB.editorRegistry) do
94-
if editorCfg.editor then
95-
Log.Notice(" Creating editor: " .. name)
96-
SB.editors[name] = editorCfg.editor()
97-
count = count + 1
98-
else
99-
Log.Warning(" Editor " .. name .. " has no constructor function")
100-
end
101-
end
102-
Log.Notice("Initialized " .. count .. " editors")
103-
end
104-
10582
function View:SetupRmlUiEvents()
10683
if not self.mainDocument then
10784
return
@@ -365,13 +342,19 @@ end
365342
function View:OpenEditor(editorName)
366343
Log.Notice("Opening editor: " .. editorName)
367344

368-
-- Editor should already be initialized during View:InitializeAllEditors()
369-
local editor = SB.editors and SB.editors[editorName]
370-
if not editor then
371-
Log.Error("Editor not initialized: " .. editorName)
372-
return
345+
-- Create editor lazily on first use
346+
if not SB.editors[editorName] then
347+
local editorCfg = SB.editorRegistry[editorName]
348+
if editorCfg and editorCfg.editor then
349+
Log.Notice(" Lazily creating editor: " .. editorName)
350+
SB.editors[editorName] = editorCfg.editor()
351+
else
352+
Log.Error("Editor not found in registry: " .. editorName)
353+
return
354+
end
373355
end
374356

357+
local editor = SB.editors[editorName]
375358
local editorCfg = SB.editorRegistry[editorName]
376359
local mainContent = self.mainDocument:GetElementById("main-content")
377360

0 commit comments

Comments
 (0)