tyoeer / Chaoshead

A level editor, scripting interface, campaign editor, and reverse engineering tool for Levelhead
Apache License 2.0
4 stars 1 forks source link

Crash after doing area deselect on stacked paths #116

Closed slothybutt closed 1 year ago

slothybutt commented 1 year ago

I was area deselecting stacked paths and got a crash. Update: It seems like this crashes if you deselect the leftover selected square directly after using the script that moves path nodes up one tile. Using the "deselect all" button does not cause a crash, nor does it cause a crash if I hit "deselect all", then reselect the tile that was selected when the crash occured, and try to recreate the crash again


Error

tools/selection/contents.lua:237: attempt to perform arithmetic on a nil value

Traceback

[love "callbacks.lua"]:228: in function 'handler'
tools/selection/contents.lua:237: in function 'removePathNodePropertiesBatch'
tools/selection/contents.lua:150: in function 'removePathNodeBatch'
tools/selection/tracker.lua:105: in function 'removeBatch'
levelEditor/levelEditor.lua:151: in function 'deselectSubArea'
levelEditor/worldEditor.lua:102: in function 'deselectArea'
levelEditor/worldEditor.lua:599: in function 'inputDeactivated'
ui/base/container.lua:137: in function 'inputDeactivated'
ui/base/container.lua:137: in function 'inputDeactivated'
ui/base/container.lua:137: in function 'inputDeactivated'
...
ui/base/container.lua:137: in function 'inputDeactivated'
main.lua:71: in function 'inputDeactivated'
libs/tyoeerUtils/input.lua:282: in function 'actionDeactivated'
libs/tyoeerUtils/input.lua:267: in function 'actionDeactivated'
libs/tyoeerUtils/input.lua:299: in function 'triggerDeactivation'
libs/tyoeerUtils/input.lua:214: in function 'mousereleased'
main.lua:89: in function <main.lua:88>
[love "callbacks.lua"]:154: in function <[love "callbacks.lua"]:144>
[C]: in function 'xpcall'```
tyoeer commented 1 year ago

More detailed cause:

After the pathUp script gets run, the editor rebuilds the selection contents from the mask. This happens in tools/selection/tracker.lua in fillContentsFromMask() , where it figures out which objects/path nodes to put in the selection by looping over all of them, using their position to determine if they should be added. When deselecting an area, it updates the selection contents by asking the world if it has something. Due to the script illegally making those differ, it doesn't re-add the node to the selection after the script is run, put does try to deselect them, and crashes.

tyoeer commented 1 year ago

This crash is the fault of the pathUp script doing something illegal do make something not completely supported, and won't be fixed in CH itself because CH is not doing anything really wrong (except perhaps letting scripts do too much).

tyoeer commented 1 year ago

On that note, here's a new pathUp.lua that breaks CH slightly different to not cause this crash:

--[[

This is not completely supported by Chaoshead. Use at your own risk.

]]

for node in selection.contents.pathNodes:iterate() do
    -- illegal decouple so it does gets overwritten
    level.pathNodes[node.x][node.y - 1] = nil
    -- can't just change the node's y due to https://github.com/tyoeer/Chaoshead/issues/116
    level:movePathNode(node, node.x, node.y - 1)
end