ACF-Team / CFW

GNU General Public License v3.0
5 stars 4 forks source link

Elastics may be causing errors during undos #1

Open Stooberton opened 2 years ago

Stooberton commented 2 years ago

During an undo, constraint.Ent1 will be NULL, breaking everything.

I have a dumb hack in place to clean it up but it is far from perfect, still breaks on some dupes.

https://github.com/Stooberton/CFW/blob/435108e854d8c0bd5aced005110d8972aacdef53/lua/cfw/core/constraints_sv.lua#L14-L67

Stooberton commented 2 years ago

The dumb hack doesn't even work on more complex contraptions.

Stooberton commented 2 years ago

There's a workaround utilizing the PreUndo hook, which actually turns out to be a great thing. If we know the contraption is going to be entirely deleted, we can go through and nicely clean up the contraption, bypassing a lot of logic.

https://github.com/Stooberton/CFW/blob/5b9c9dd59b4b84b50c0cf765b010e78f9624e2fe/lua/cfw/core/constraints_sv.lua#L59-L90

I've also added a Defuse method to the contraption class to safely defuse and remove contraptions that experience the error, which still happens in a currently unknown scenario.