NullReferenceException in automatic outlining

SyntaxEditor for Windows Forms Forum

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

Hi,

we stumbled upon another threading-issue within our test suite. It seems that the editor instance is disposed on the main thread, while the parser thread tries to update the automatic outlining. In our case it is in combination with the C# language add-on, but the problem applies to all languages with automatic outlining.

It isn't easy to reproduce, but never the less the access to variables that are used in different threads should be synchronized. Additionally we are going to wait for the parser thread, before we call dispose to avoid any other unforseen problems.

Exception message: System.NullReferenceException: Object reference not set to an instance of an object.
   at ActiproSoftware.SyntaxEditor.Document.PerformAutomaticOutlining(TextRange parseTextRange, AutomaticOutliningBehavior behavior, DocumentModification modification, Boolean isProgrammaticTextReplacement)
   at ActiproSoftware.SyntaxEditor.Document.#AAh(ISemanticParseData value, TextRange parseTextRange, Boolean isProgrammaticTextReplacement, Object requestSyncRoot)
   at ActiproSoftware.SyntaxEditor.Document.#fAh(SemanticParserServiceRequest request)
   at ActiproSoftware.SyntaxEditor.SemanticParserService.#Jth(SemanticParserServiceRequest request)
   at ActiproSoftware.SyntaxEditor.SemanticParserService.#Kth()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()


Best regards, Tobias Lingemann.

Comments (4)

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

Hi Tobias,

We do have some thread sync code in there, but I see one thing that could be improved.  Which version are you using, is it the latest v14.1.0322 as your post indicates?


Actipro Software Support

Posted 4 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

We are using the build 320, but I've checked all changes in 321 and 322. The problem remains the same. The PerformAutomaticOutlining method is called in the parser thread and the dispose is called in the main thread. During the dispose the language is set to null. It is not enough to check the reference for null, since this isn't an atomic operation. You could copy the reference via Interlocked.Exchange() but the best way is really to use locks. The dispose call should wait if the PerformAutomaticOutlining method is running and vice versa if the dispose call came in first.


Best regards, Tobias Lingemann.

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

Hi Tobias,

The reference copy was what we were thinking could be improved there.  Ordinarily I would also agree that a lock could be added to Dispose but I am hesitant to add that since it is a Dispose method, which could be called by the developer or system.  I worry that a lock there could cause stability issues in the framework in certain scenarios, so we will add the reference copy within PerformAutomaticOutlining.


Actipro Software Support

Posted 4 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Yes, I think that will work. My only concern is that everyone who handles the AutomaticOutliningComplete event and the method SyntaxLanguage.OnDocumentAutomaticOutliningComplete(). Both need to know that the caller might already be disposed and check that accordingly. But thats something we can work with.


Best regards, Tobias Lingemann.

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.