Skip to content

Commit 0820678

Browse files
committed
Add guards for field operations in RmlUi mode
Fixed more editor errors when fields don't have Chili methods: Editor.lua fixes: - _AddField: Guard against nil field or missing field.name - Set: Guard against nil field, make Set() method optional - Update: Make Update() method optional (only exists on Chili fields) object_property_window.lua fix: - Guard stackPanel access when bridge is nil These changes allow editors to work with simple field tables in RmlUi mode: - Fields can be added without Chili methods - editor:Set() works with both Chili fields and plain tables - editor:Update() doesn't crash on plain field tables - No more crashes when editors instantiate
1 parent 7fdffe5 commit 0820678

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

scen_edit/view/editor.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ function Editor:AddField(field)
360360
end
361361

362362
function Editor:_AddField(field)
363+
if not field or not field.name then
364+
Log.Error("Attempted to add field without name")
365+
return
366+
end
363367
self.fields[field.name] = field
364368
field.ev = self
365369
end
@@ -416,13 +420,26 @@ end
416420
-- self:Set("myNumber", 15)
417421
function Editor:Set(name, value)
418422
local field = self.fields[name]
419-
field:Set(value)
423+
if not field then
424+
Log.Warning("Attempted to set non-existent field: " .. tostring(name))
425+
return
426+
end
427+
-- Only call Set if the method exists (Chili fields)
428+
if field.Set then
429+
field:Set(value)
430+
else
431+
-- For RmlUi fields, just set the value directly
432+
field.value = value
433+
end
420434
end
421435
function Editor:Update(name, _source)
422436
local field = self.fields[name]
423437
assert(field, "No such field to update: " .. tostring(name))
424438

425-
field:Update(_source)
439+
-- Only call Update if the method exists (Chili fields)
440+
if field.Update then
441+
field:Update(_source)
442+
end
426443

427444
-- update listeners and current state
428445
if not self.__initializing then

scen_edit/view/object/object_property_window.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,10 @@ function ObjectPropertyWindow:OnSelectionChanged()
568568
end
569569

570570
if not bridge then
571-
self.stackPanel:EnableRealign()
572-
self.stackPanel:Invalidate()
571+
if self.stackPanel then
572+
self.stackPanel:EnableRealign()
573+
self.stackPanel:Invalidate()
574+
end
573575
return
574576
end
575577

0 commit comments

Comments
 (0)