Dotneteer / spectnetide

ZX Spectrum IDE with Visual Studio 2017 and 2019 integration
MIT License
206 stars 27 forks source link

Crashes editing basic files #185

Closed gusmanb closed 4 years ago

gusmanb commented 4 years ago

Hi. I'm having a lot of VS crashes editing ZX Basic files.

The first one I can replicate consistently is cutting code. Whenever I cut more than two or three lines VS always crashes with no message. On EventViewer I can see this:

Información de la excepción: System.ArgumentOutOfRangeException
   en Microsoft.VisualStudio.Text.Implementation.BinaryStringRebuilder.GetText(Microsoft.VisualStudio.Text.Span)
   en Microsoft.VisualStudio.Text.Implementation.CachingTextImage.GetText(Microsoft.VisualStudio.Text.Span)
   en Microsoft.VisualStudio.Text.Implementation.BaseSnapshot.GetText(Int32, Int32)
   en Spect.Net.VsPackage.LanguageServices.ZxBasic.ZxBasicParserListener.ExitAsm_section(Asm_sectionContext)
   en Spect.Net.BasicParser.Generated.ZxBasicParser+Asm_sectionContext.ExitRule(Antlr4.Runtime.Tree.IParseTreeListener)
   en Antlr4.Runtime.Tree.ParseTreeWalker.ExitRule(Antlr4.Runtime.Tree.IParseTreeListener, Antlr4.Runtime.Tree.IRuleNode)
   en Antlr4.Runtime.Tree.ParseTreeWalker.Walk(Antlr4.Runtime.Tree.IParseTreeListener, Antlr4.Runtime.Tree.IParseTree)
   en Spect.Net.VsPackage.LanguageServices.ZxBasic.ZxBasicClassifier.<ParseDocument>b__43_1()
   en System.Threading.Tasks.Task.InnerInvoke()
   en System.Threading.Tasks.Task.Execute()
   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   en Spect.Net.VsPackage.LanguageServices.ZxBasic.ZxBasicClassifier+<<ParseDocument>g__DoParse|43_0>d.MoveNext()
   en System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
   en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
   en Spect.Net.VsPackage.LanguageServices.ZxBasic.ZxBasicClassifier+<ParseDocument>d__43.MoveNext()
   en System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0(System.Object)
   en System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   en System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   en System.Windows.Threading.DispatcherOperation.InvokeImpl()
   en System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   en MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)
   en System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   en System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   en System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   en MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
   en System.Windows.Threading.DispatcherOperation.Invoke()
   en System.Windows.Threading.Dispatcher.ProcessQueue()
   en System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   en MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   en MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   en System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   en System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   en System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   en MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

Also when I delete or paste code some times the same happens, the IDE crashes and I have the exact same error on the event viewer.

I think this error started happening since the last VS update.

Cheers.

Dotneteer commented 4 years ago

@gusmanb, can you help me to create something reproducible? For example, you have a ZX BASIC file, and when you type something at a particular location, VS crashes. If I have thes instructions for reproduction, I can check whether this issue is in VS 2019 or in SpectNetIDE.

gusmanb commented 4 years ago

Hi.

This is the project I'm working right now (a little basic game for the speccy)

IslaTesoroCrash.zip

I'm attaching this because on a small, new project I'm unable to reproduce it but in other bigger projects I have I get the same exception.

To crash the IDE do this: Open "IslaTesoro.zxbas" file, cut 3 or 4 lines and try to paste the lines. On my computer it crases 100% of the time, sometimes even before trying to paste.

Cheers.

Dotneteer commented 4 years ago

Thanks, @gusmanb, I managed to reproduce the issue! :-)

Dotneteer commented 4 years ago

@gusmanb, it was a nasty VS bug :-(, an error in concurrency handling. It caused crashes when you do some actions (like cut and paste, or copy and paste) quickly after each other. I managed to create some workaround, and hopefully it solves the crashing issue. Here I attach a private build so that you can try the fix. Please, rename it to .vsix!

Spect.Net.VsPackage.zip

gusmanb commented 4 years ago

Installed and working 👍 I've been testing it cutting and pasting pieces of basic and for now I got zero crashes.

I will be working on the speccy project all the day so I will test it extensively 😄

Cheers.

Dotneteer commented 4 years ago

If you have any issues, please, report it. Tomorrow I plan to release the next Preview with all fixes I've done so far.

gusmanb commented 4 years ago

I've been working all the day on my project, cutting, pasting, replacing code, etc, and I had no single crash, so I'm going to close the issue 😄

Cheers.