VBAndCs / sVB-Small-Visual-Basic

Small Visual Basic (sVB) is an educational programming language, created by Eng. Mohammad Hamdy as an evolved version of Microsoft Small Basic (SB). It is meant to be easier and more powerful at the same time, to introduce programming basics to kids and beginners of any age, provided that they can use the English keyboard on the Windows OS.
Other
222 stars 16 forks source link

Cut (to clipboard) of text in code window will *sometimes* cause sVB to crash #17

Closed sjsepan3 closed 1 year ago

sjsepan3 commented 1 year ago

While editing code in one of the code windows in the Code tab, highlight some code and do Ctrl-X to Cut. If the code is cut immediately, you are OK. However, if it does not, wait and within ~5 seconds a dialog will appear telling you that the program has stopped working and it is checking for solutions - after a short while it will all close, including sVB.

I first observed this in sVB 2.8.0 ... 2.8.3, but was occupied with learning the language/ide. I determined to report it with 2.8.4 since I had finished a project. I was able to see it happen once in 2.8.4, but not repeatably yet. (In earlier versions it seemed to happen nearly every time I forgot myself and tried to cut&paste some code within the editor.)

While I was experiencing it frequently, I was beginning to get the impression that it might be a conflict caused by my trying to remove text just as the Intellisense was trying to evaluate it, but I cannot recreate it enough now to be sure. I have not seen this happen in the form designer when cutting a control.

Windows 7 SP1, running in VirtualBox 6.1.38_Ubuntu r153438, on Linux Mint 21.2 Cinnamon

UPDATE: I went back and un-installed/re-installed older versions, 2.8.3 .. 2.8.1 and cannot recreate with the sequence that I used to see it the one time in 2.8.4. So until I can find a scenario that causes it more frequently, I can only say that it is intermittent.

VBAndCs commented 1 year ago

@sjsepan3 Usually it relates to the Code editor, which has two versions of the text, and some methods sees the older version which causes issues in the Intellisens. I thought I've fixed that, but seems I need to dig more. There is also some issue when you copy a word from the code editor to Word, as it pastes the rest of the line, unless you ask word to paste the text withoout any format, but I was lazy to fix it :) I'll try to find the source of the crash. Thanks.

VBAndCs commented 1 year ago

@sjsepan3 Can you give me some of the code that causes the issue, and the place that you cut at? Also, is your PC somehow slow or busy during this? I make the intellisense wait for a few milliseconds to allow the code editor to update itself, but this may not be enough on a busy PC. I can't reproduce this error until now. And by the way, don't mind sVB versions, because I didn't change anything in the code editor for a while.

VBAndCs commented 1 year ago

I changed something in the auto-completion delay, so that it waits until all tasks complete. Please uninstall sVB and download this zip file. Try coding using this sVB version for a while, and test the cut command heavily. I will try this modification for a while until I think it is stable to publish. Thanks.

[Uploading sVB_Trial.zip…]()

VBAndCs commented 1 year ago

@sjsepan3 I expect the cut crash happens for you when you cut lines from the end of the file. Please try cutting words and lines from all possible locations, specially end of lines and end of page.

sjsepan3 commented 1 year ago

@sjsepan3 Can you give me some of the code that causes the issue, and the place that you cut at? Also, is your PC somehow slow or busy during this?

It may have been busy when I was working with the project, but in the case of 2.8.4, and th eone time today I was able to make it happen, it was the simplest case imaginable: I opened sVB to a blank project, opened Global.sb, typed in

this is a test

Hit Tab, which turned "test" into "UnitTest", hit Home and typed in a single-quote ('), doubled-clicked "unitTest and type Ctrl-X. But I was not able to repeat the incident with that scenario or several variations.

But I will also download the link you posted below and let you know what I see...

sjsepan3 commented 1 year ago

I expect the cut crash happens for you when you cut lines from the end of the file. Please try cutting words and lines from all possible locations, specially end of lines and end of page.

OK, I will try those scenarios with 2.8.4 and with the Trial version...

VBAndCs commented 1 year ago

@sjsepan3

this is a test

Hit Tab, which turned "test" into "UnitTest", hit Home and typed in a single-quote ('), doubled-clicked "unitTest and type Ctrl-X. But I was not able to repeat the incident with that scenario or several variations.

This doesn't cause any problem with me. Try to get the details of the exception that crashes the app, like you did before, so that we can get an idea about what is happening. Also, this bug that only occur for the first time, may indicate that this the Anti virus thing. On my device, the sVB version that is installed in the program files folder, is closed and re-opened after a few seconds from showing the form designer, and this happens only the first time after installing a new version. This is the doing of the Avast antivirus.

sjsepan3 commented 1 year ago

Try to get the details of the exception that crashes the app, like you did before, so that we can get an idea about what is happening.

@VBAndCs Ah, Yes, I forgot about that...here:

two entries in the log for that one incident...


Faulting application name: sVB.exe, version: 2.8.4.0, time stamp: 0x6469f963 Faulting module name: KERNELBASE.dll, version: 6.1.7601.24384, time stamp: 0x5c6e248c Exception code: 0xe0434352 Fault offset: 0x000000000000be0d Faulting process id: 0xd5c Faulting application start time: 0x01d98ca39f23fd85 Faulting application path: C:\Program Files (x86)\Small Visual Basic\sVB\Bin\sVB.exe Faulting module path: C:\Windows\system32\KERNELBASE.dll Report Id: 0c71c9f9-f897-11ed-b199-080027a1eb77


Application: sVB.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Runtime.InteropServices.COMException at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32, IntPtr) at System.Windows.Clipboard.Flush() at System.Windows.Clipboard.CriticalSetDataObject(System.Object, Boolean) at Microsoft.Nautilus.Text.Operations.EditorCommands.CopyHandler(Microsoft.Nautilus.Text.Editor.IAvalonTextView) at Microsoft.Nautilus.Text.Operations.EditorCommands.CutHandler(Microsoft.Nautilus.Text.Editor.IAvalonTextView) at Microsoft.Nautilus.Text.Editor.DefaultKeyboardFilter.KeyDown(Microsoft.Nautilus.Text.Editor.IAvalonTextView, System.Windows.Input.KeyEventArgs) at Microsoft.Nautilus.Text.Editor.AvalonTextViewHost.OnKeyDown(System.Object, System.Windows.Input.KeyEventArgs) at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean) at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs) at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs) at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport) at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawKeyboardActions, Int32, Boolean, Boolean, Int32) at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(System.Windows.Interop.MSG ByRef, Boolean ByRef) at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(System.Windows.Interop.MSG ByRef, System.Windows.Input.ModifierKeys) at System.Windows.Interop.HwndSource.OnPreprocessMessage(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate, System.Object) at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(System.Windows.Interop.MSG ByRef, Boolean ByRef) at System.Windows.Interop.ThreadMessageEventHandler.Invoke(System.Windows.Interop.MSG ByRef, Boolean ByRef) at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at Microsoft.SmallVisualBasic.App.Main()


sjsepan3 commented 1 year ago

This is the doing of the Avast antivirus.

@VBAndCs In my Win7 VM, its ClamWin running, but it could be a similar behavior.

sjsepan3 commented 1 year ago

Uploading sVB_Trial.zip…

@VBAndCs The link just seems to come back to this issue page.

So, I did the recommended scenario with the version 2.8.4 that I have, and have not re-created the incident yet.

VBAndCs commented 1 year ago

@sjsepan3 This seems an expected exception while trying to write date to the clipboard, which I saw others complain about in stack overflow. This may happen because another app tries to write data in the clipboard or has a protected data somehow, or maybe the anti virus or windows security are checking something. This doesn't happen on my PC, but the lesson here is that one should always use the Try catch exception handler block when he tries to deal with the clipboard (for both writing and reading). I did this, so such exception would not crash the app, instead a message will tell you to try again. You can try this with this version, and if it is OK, I will update the installer: sVB_Trial 2.zip

sjsepan3 commented 1 year ago

You can try this with this version, and if it is OK,

@VBAndCs I have done a test with it and no errors. Since there was no message, I conclude the incident did not happen, as otherwise there would be an error message. I will try some more later, to be sure.

UPDATE: I cannot recreate the issue, and there were no new errors.

VBAndCs commented 1 year ago

@sjsepan3 I just published sVB 2.8.4.1, where this bug is fixed. When writing data to the clipboard fails, sVB will try writing again 4 more times, with a 20ms delay intervals, before displaying a message to the user. I will close this issue, but if the error happens again, please notify me.

sjsepan3 commented 1 year ago

I will close this issue, but if the error happens again, please notify me.

OK, sounds good -- Thanks!