Crash in element:update() after replacing element.layout

Issue Description

Crash during element:update() after replacing element.layout

Catching it in the debugger shows the crash happens at element.cpp:303, with parent = null

Steps to Reproduce

Attach the following script to PLAYER

local ui = require('openmw.ui')
local test = ui.create({})

local function onUpdate(dt)
    test.layout = {
        type = ui.TYPE.Text,
        props = {text = tostring(dt)},
        layer = 'Popup',
    }
    test:update()
end
return {
    engineHandlers = {onUpdate = onUpdate}
}

And load into any game, it crashes

Interestingly: It does not crash if you comment out test:update(), load into a game, uncomment it, and then do reloadlua

System Information

  • **OpenMW Version: 3d763e73
  • Operating System & Version: Arch linux

Mods

  • Are you using mods? Only the script included in this ticket
  • Are you using any shader mods? No
  • Does it happen in a clean vanilla install? Untested

Logs and Settings

Nothing useful in the logs, doesn't seem settings related