Reload File and Refresh Intellisense crash

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Adam Dickinson
Avatar
SyntaxEditor v3.1.203

I am getting a weird crash. We're using your Syntax Editor in our scripting IDE and I've implemented a Find/Replace in Files dialog box. On a Replace All (which runs in its own thread), words are replaced outside of the editor, and open files are reloaded to view the changes. Then, we refresh the intellisense for the file associated with the active tab, dynamically changing the Language specification to pick up changed syntax keywords.

The crash does not occur 100% of the time and has 3 incarnations. When the crash occurs, I can elect to Continue at which point I get a stack dump for where the exception occurred:

CASE 1:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Index was out of range.  Must be non-negative and less than the size of the collection.


Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range.  Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.get_Item(Int32 index)
   at ActiproSoftware.SyntaxEditor.DocumentLineCollection.get_Item(Int32 index)
   at ActiproSoftware.SyntaxEditor.EditorView._2(Graphics , Rectangle )
   at ActiproSoftware.SyntaxEditor.EditorView.OnRender(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIElement.Render(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl.OnRenderChildElements(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl.Render(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl._1(PaintEventArgs )
   at ActiproSoftware.WinUICore.UIControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at ActiproSoftware.SyntaxEditor.SyntaxEditor.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at ragScriptEditor.Form1.Main(String[] args) in c:\soft\rage\script\tools\ragscripteditor\form1.cs:line 25An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll

Additional information: Cannot call Invoke or InvokeAsync on a control until the window handle has been created.

23
Unhandled Exception: System.InvalidOperationException: Cannot call Invoke or InvokeAsync on a control until the window handle has been created.
   at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   at ScriptComponent.FindReplaceAllForm.ReplaceDone(Int32 totalFound, Int32 matchingFiles, Int32 totalFilesSearched, EFindNextReturnTypes err, String errorString1, String errorString2) in c:\soft\rage\script\tools\ragscripteditor\ragcomponent\findreplaceallform.cs:line 1125
   at WinSearchFile.FindReplace.ReplaceAllInClosedDoc(String fileName, FindReplaceOptions findReplaceOptions, Form theForm, AddFoundStringDelegate foundStringDel, String& errorString1, String& errorString2, SearchDoneDelegate searchDoneDel) in C:\soft\rage\script\tools\ragScriptEditor\ragComponent\FileSearch.cs:line 1202
   at WinSearchFile.FindReplace.ClosedDocSearchReplace() in C:\soft\rage\scriptThe thread '<No Name>' (0x1110) has exited with code 0 (0x0).
\tools\ragScriptEditor\ragComponent\FileSearch.cs:line 774The program '[3160] ragScriptEditor.exe' has exited with code 0 (0x0).
CASE 2:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

Additional information: Index was out of range.  Must be non-negative and less than the size of the collection.


Unhandled Exception: System.ArgumentOutOfRangeException: Index was out of range.  Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.get_Item(Int32 index)
   at ActiproSoftware.SyntaxEditor.DisplayLineCollection.get_Item(Int32 index)
   at ActiproSoftware.SyntaxEditor.EditorView._2(Graphics , Rectangle )
   at ActiproSoftware.SyntaxEditor.EditorView.OnRender(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIElement.Render(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl.OnRenderChildElements(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl.Render(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl._1(PaintEventArgs )
   at ActiproSoftware.WinUICore.UIControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at ActiproSoftware.SyntaxEditor.SyntaxEditor.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at ragScriptEditor.Form1.Main(String[] args) in c:\soft\rage\script\tools\ragscripteditor\form1.cs:line 2523The program '[2632] ragScriptEditor.exe' has exited with code 0 (0x0).
CASE 3:

An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll

Additional information: Object reference not set to an instance of an object.


Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at ActiproSoftware.SyntaxEditor.Token.get_Language()
   at ActiproSoftware.SyntaxEditor.EditorView._1(Graphics , Rectangle , DocumentLine , Int32 , DisplayLine , _42 , Rectangle , Int32 )
   at ActiproSoftware.SyntaxEditor.EditorView._2(Graphics , Rectangle )
   at ActiproSoftware.SyntaxEditor.EditorView.OnRender(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIElement.Render(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl.OnRenderChildElements(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl.Render(PaintEventArgs e)
   at ActiproSoftware.WinUICore.UIControl._1(PaintEventArgs )
   at ActiproSoftware.WinUICore.UIControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message&An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll

Additional information: Cannot call Invoke or InvokeAsync on a control until the window handle has been created.

 m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at ActiproSoftware.SyntaxEditor.SyntaxEditor.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at ragScriptEditor.Form1.Main(String[] args) in c:\soft\rage\script\tools\ragscripteditor\form1.cs:line 2523
Unhandled Exception: System.InvalidOperationException: Cannot call Invoke or InvokeAsync on a control until the window handle has been created.
   at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
   at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
   at ScriptComponent.FindReplaceAllForm.ReplaceDone(Int32 totalFound, Int32 matchingFiles, Int32 totalFilesSearched, EFindNextReturnTypes err, String errorString1, String errorString2) in c:\soft\rage\script\tools\ragscripteditor\ragcomponent\findreplaceallform.cs:line 1125
   at WinSearchFile.FindReplace.ReplaceAllInClosedDoc(String fileName, FindReplaceOptions findReplaceOptions, Form theForm, AddFoundStringDelegate foundStringDel, String& errorString1, String& errorString2, SearchDoneDelegate searchDoneDel) in C:\soft\rage\script\tools\ragScriptEditor\ragComponent\FileSearch.cs:line 1202
   at WinSearchFile.FindReplace.ClosedDocSearchReplace() in C:\soft\rage\scriptThe thread '<No Name>' (0x15a0) has exited with code 0 (0x0).
\tools\ragScriptEditor\ragComponent\FileSearch.cs:line 774The program '[3672] ragScriptEditor.exe' has exited with code 0 (0x0).
Unfortunately, I can't send you the code for our app as it is propriety, quite complex, and at the moment, I don't have time to strip it down to build a sample app to demo the bug. But I can tell you I've tracked it down to some consequence of my intellisense refreshing (which works fine under all other circumstances it is used).

Instead, does anyone know of situations in which the above exceptions might occur? Specifically, what is the correct procedure for reloading a file? What are the correct steps to dynamically add/remove LexicalPatternGroups to/from the document's Language? What about syntax color highlighting? When is the proper time to update that?

Thanks.

[Modified at 05/02/2006 05:59 PM]

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Adam,

My guess is that the problem is your multi-threading. Say for instance the editor is in
the middle of painting a line (which it has to do with each caret blink) and you are using
a secondary thread to update text, thereby changing tokens. The painting code will probably
blow up like in your case #1. I bet you that's what's going on.

Are you trying to Invoke a call to UndoableInsert after your replace all operation?

Also, language changes need to be done on the main UI thread as well. You need to call
"editor.Document.Language.IsUpdating = true" before making any pattern group changes and
"editor.Document.Language.IsUpdating = false" afterwards. But again, that needs to be done
on the main thread. So if you are doing it from the secondary thread, please try moving that
code to the main one.


Actipro Software Support

Posted 13 years ago by Adam Dickinson
Avatar
We're not calling UndoableInsert, and we're handling the Language.IsUpdating properly. It was the threading. Thanks!
The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.