NullReferenceException in parser thread after editor is disposed

SyntaxEditor for Windows Forms Forum

Posted 5 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 13.1.0312
Platform: Universal Windows Controls
Environment: Windows 7 (64-bit)
Avatar

Hi,

from time to time we get a NullReferenceException from a closed editor in the semantic parser thread. I think the problem is that after disposing the editor, the document is null, which is not handled correctly when the semantic parse data is updated.

We already tried to remove pending requests from the parser thread, but I doesn't work if the parser is already running.

string hashKey = SemanticParserServiceRequest.GetParseHashKey(EditorDocument, EditorDocument);
SemanticParserService.RemovePendingRequests(hashKey);

 Here is the callstack:

Exception message: System.NullReferenceException:
at ActiproSoftware.SyntaxEditor.SyntaxEditor.b(Int32 A_0, Int32 A_1)
at ActiproSoftware.SyntaxEditor.SyntaxEditor.a(EventArgs A_0)
at ActiproSoftware.SyntaxEditor.SyntaxEditor.k(Object A_0, EventArgs A_1)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at ActiproSoftware.SyntaxEditor.Document.OnSemanticParseDataChanged(EventArgs e)
at ActiproSoftware.SyntaxEditor.Document.a(ISemanticParseData A_0, TextRange A_1, Boolean A_2, Object A_3)
at ActiproSoftware.SyntaxEditor.Document.ActiproSoftware.SyntaxEditor.ISemanticParseDataTarget.NotifySemanticParseComplete(SemanticParserServiceRequest request)
at ActiproSoftware.SyntaxEditor.SemanticParserService.a(SemanticParserServiceRequest A_0)
at ActiproSoftware.SyntaxEditor.SemanticParserService.c()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() System.NullReferenceException. Void b(Int32, Int32) 

Update:

I think the problem is the order in which the editor disposes its resources. The semantic parse changed event probably arrives between step 1 and step 2. During that timespan, a call of StartUniversalTimer() leads to the exception. The event handler already checks if the object is disposed, but the flag is set in step 3 when the base class is disposed. It would be better to check for the private flag 'disposing'.

protected override void Dispose(bool disposing) {
  ...
  this.DisposeUniversalTimer();     // <-- step 1
  ...
  this.SetDocument(null);           // <-- step 2
  ...
  base.Dispose(disposing);          // <-- step 3
  ...
}

[Modified 5 years ago]


Best regards, Tobias Lingemann.

Comments (1)

Answer - Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tobias,

Thanks for reporting this.  We've updated the StartUniversalThread method to prevent this exception.  It will be in the next release.


Actipro Software Support

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.