Script draw() called when hovering over editor UI while state machine is stopped
A Node Script's `draw()` function is being called when the user hovers over editor UI elements (property panel fields, buttons, etc.), even when the state machine is completely stopped. This causes scripts to continue executing rendering code unexpectedly.
- moving the mouse of non-interactive elements of the ui - like blank canvas or areas that do not have hover interactions - i.e. fields that can’t be edited) does not cause `draw()`
--!strict
export type BugDemo = {
drawCount: number,
stopped: boolean,
path: Path,
}
function init(self: BugDemo): boolean
print('Start state machine, then stop it, then hover over editor UI')
self.drawCount = 0
self.stopped = false
self.path = Path.new()
return true
end
function advance(self: BugDemo, seconds: number): boolean
if self.drawCount > 60 then
self.stopped = true
print('STOPPED - now hover over editor UI elements')
return false
end
return true
end
function draw(self: BugDemo, renderer: Renderer)
self.drawCount = self.drawCount + 1
if self.stopped then
print('[BUG] draw() called while stopped! count = ' .. self.drawCount)
end
local size = 20 + self.drawCount
self.path:reset()
self.path:moveTo(Vector.xy(-size, -size))
self.path:lineTo(Vector.xy(size, -size))
self.path:lineTo(Vector.xy(size, size))
self.path:lineTo(Vector.xy(-size, size))
self.path:close()
local paint = Paint.with({
style = 'fill',
color = if self.stopped then Color.rgb(0, 255, 0) else Color.rgb(255, 0, 0),
})
renderer:drawPath(self.path, paint)
end
return function(): Node<BugDemo>
return {
init = init,
advance = advance,
draw = draw,
drawCount = 0,
stopped = false,
path = late(),
}
end