tooll3 / t3

Tooll 3 is an open source software to create realtime motion graphics.
MIT License
3.48k stars 192 forks source link

Crash after duplicating as new Symbol #471

Open pixtur opened 1 month ago

pixtur commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

Please complete the following information):

To Reproduce Steps to reproduce the behavior:

  1. Create [Modulo]
  2. Right-click -> Symbol -> Duplicate as new Type
  3. Crash:

image

after resume... image

image

pixtur commented 1 month ago

On release if get the following stacktrace in the crash-reporter:

On noooo, how embarrassing! T3 just crashed
Last backup was saved 1 minutes ago to .t3/backups/
Please consult the Wiki on what to do next.

When this window closes, the current operator will be copied to your clipboard. You can use it to troubleshoot/reproduce the issue.

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at System.Collections.Generic.List`1.RemoveAt(Int32 index)
   at T3.Core.Operator.Symbol.DestroyInstance(Instance instance, Int32 index) in C:\Users\pixtur\dev\tooll\t3-main\Core\Operator\Symbol.cs:line 113
   at T3.Core.Operator.Symbol.DestroyInstance(Instance instance, Int32 index) in C:\Users\pixtur\dev\tooll\t3-main\Core\Operator\Symbol.cs:line 106
   at T3.Core.Operator.Symbol.DestroyInstance(Instance instance, Int32 index) in C:\Users\pixtur\dev\tooll\t3-main\Core\Operator\Symbol.cs:line 106
   at T3.Core.Operator.Symbol.UpdateInstanceType() in C:\Users\pixtur\dev\tooll\t3-main\Core\Operator\Symbol.TypeUpdating.cs:line 40
   at T3.Core.Model.SymbolPackage.UpdateSymbolInstances(Symbol symbol) in C:\Users\pixtur\dev\tooll\t3-main\Core\Model\SymbolPackage.cs:line 263
   at T3.Core.Model.SymbolPackage.LoadSymbols(Boolean parallel, List`1& newlyRead, List`1& allNewSymbols) in C:\Users\pixtur\dev\tooll\t3-main\Core\Model\SymbolPackage.cs:line 163
   at T3.Editor.Compilation.ProjectSetup.UpdateSymbolPackages(PackageWithReleaseInfo[] packages) in C:\Users\pixtur\dev\tooll\t3-main\Editor\Compilation\ProjectSetup.cs:line 238
   at T3.Editor.Compilation.ProjectSetup.UpdateSymbolPackage[T](T project) in C:\Users\pixtur\dev\tooll\t3-main\Editor\Compilation\ProjectSetup.cs:line 179
   at T3.Editor.UiModel.EditableSymbolProject.TryCompile(String sourceCode, String newSymbolName, Guid newSymbolId, String nameSpace, Symbol& newSymbol, SymbolUi& newSymbolUi) in C:\Users\pixtur\dev\tooll\t3-main\Editor\UiModel\EditableSymbolProject.Recompilation.cs:line 52
   at T3.Editor.Gui.Graph.Modification.Duplicate.DuplicateAsNewType(SymbolUi compositionUi, EditableSymbolProject project, Guid symbolId, String newTypeName, String nameSpace, String description, Vector2 posOnCanvas) in C:\Users\pixtur\dev\tooll\t3-main\Editor\Gui\Graph\Modification\Duplicate.cs:line 51
   at T3.Editor.Gui.Graph.GraphCanvas.DrawGraph(ImDrawListPtr drawList, GraphDrawingFlags drawingFlags, Boolean preventInteractions, Single graphOpacity)
   at T3.Editor.Gui.Graph.GraphWindow.DrawContent() in C:\Users\pixtur\dev\tooll\t3-main\Editor\Gui\Graph\GraphWindow.cs:line 177
   at T3.Editor.Gui.Windows.Window.Draw() in C:\Users\pixtur\dev\tooll\t3-main\Editor\Gui\Windows\Window.cs:line 46
   at T3.Editor.Gui.Windows.Layouts.WindowManager.Draw() in C:\Users\pixtur\dev\tooll\t3-main\Editor\Gui\Windows\Layouts\WindowManager.cs:line 36
   at T3.Editor.Gui.T3Ui.ProcessFrame() in C:\Users\pixtur\dev\tooll\t3-main\Editor\Gui\T3UI.cs:line 122
   at T3.Editor.Gui.WindowsUiContentDrawer.RenderCallback() in C:\Users\pixtur\dev\tooll\t3-main\Editor\Gui\WindowsUiContentDrawer.cs:line 159
   at SharpDX.Windows.RenderLoop.Run(Control form, RenderCallback renderCallback, Boolean useApplicationDoEvents)
   at T3.Editor.App.AppWindow.RunRenderLoop(Action callback) in C:\Users\pixtur\dev\tooll\t3-main\Editor\App\AppWindow.cs:line 111
   at T3.Editor.Program.Main(String[] args) in C:\Users\pixtur\dev\tooll\t3-main\Editor\Program.cs:line 184

Which leads to Symbol.cs -> DestroyInstance()

        private void DestroyInstance(Instance instance, int index = -1)
        {
            var allChildren = instance.ChildInstances.Values.ToArray();
            foreach (var child in allChildren)
            {
                child.Symbol.DestroyInstance(child);
            }

            instance.Parent?.ChildInstances.Remove(instance.SymbolChildId);
            instance.Dispose();

            index = index == -1 ? _instancesOfSelf.IndexOf(instance) : index;
            _instancesOfSelf.RemoveAt(index);  // <------------
        }