Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) DiagramLink.MRT(Point, MouseButton) null exception (Read 2302 times)
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
DiagramLink.MRT(Point, MouseButton) null exception
Jun 13th, 2025 at 8:42am
Print Post  
Hello,

In our tool we are using the mindfusion.diagramming.wpf version 4.1.9

Once the link has been created it is allowed to delete it. The issue is that if later I would hit the left mouse button over the deleted link route the tool crashes due to given mindfusion callstack.

Moreover I override the OnLinkSelecting on my diagram class. It shows that the Items does not contain the link but somehow it is allowed to select it. In result an exception is throwed.

I guess that this link is stored somewhere in memory but couldnt find a right place to check...

The origin and desination are dummy nodes so it means as far as I know it was created without setting any origin and destination.

If there is anything I can do to avoid this situation please let me know.
  

callstack.png ( 61 KB | 71 Downloads )
callstack.png
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #1 - Jun 13th, 2025 at 8:43am
Print Post  
The overriden OnLinkSelecting
  

ItemsDoesNotContain.png ( 78 KB | 68 Downloads )
ItemsDoesNotContain.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #2 - Jun 13th, 2025 at 9:24am
Print Post  
Hi,

I cannot reproduce that in vanilla configuration by click-selecting a link, pressing Del, clicking again. In what manner are you deleting? I imagine that exception would happen if deletion process is somehow interrupted after setting link.Parent to null but before removing from diagram.Items, maybe if another exception is thrown by delete-related event handler but caught and ignored up the call stack.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #3 - Jun 13th, 2025 at 10:14am
Print Post  
The links is removed succesfuly - it is not contained in diagram.Items anymore also not visible on view.

It looks like something is still keeping a diagram link in memory and looking at the cotract of this MRT I think its related with selection.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #4 - Jun 13th, 2025 at 12:51pm
Print Post  
Do you mean deleting by pressing Del key, or removing from code behind? Does your application override links' OnRemove method by any chance?
  
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #5 - Jun 13th, 2025 at 1:27pm
Print Post  
We are removing it from the diagram by a command that is bounded to our viewmodel. In result after few additional cleanups on our site we are calling simply Links.Remove(link).

We dont override the OnRemove. But we are subscribed to this event so I know it was called at least once after deleting the link.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #6 - Jun 16th, 2025 at 6:02am
Print Post  
Sorry, we could not reproduce. Please copy your diagram properties and event handlers to this test project, and attach it back when the exception happens for our developer to investigate.

Regards,
Slavcho
Mindfusion
  

WpfApp4.zip ( 3 KB | 61 Downloads )
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #7 - Jul 25th, 2025 at 10:50am
Print Post  
Dear Slavcho,

I was able to avoid the exception.
I override the HitTest on our LinkView class

(LinkView : DiagramLink)

      public override DiagramItem HitTest(Point point, double threshold, bool onlyNodes, bool onlyInteractive, bool includeHandles, bool includeLabels)
      {
         var what = base.HitTest(point, threshold, onlyNodes, onlyInteractive, includeHandles, includeLabels);
         if (what?.Parent == null)
         {
            return null;
         }

         return what;
      }

So..

The Parent (diagram) was null for the link that was somehow kept in the memory.

The diagram that we are using shows that Items collection does not contain this link. Same as Links collection.

So it was kept somewhere in memory so the HitTest was returning it when hovering on the diagram over its previous route.

Maybe it will helps you Smiley
Cheers

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #8 - Jul 25th, 2025 at 12:38pm
Print Post  
Dear Patryk,

Are you using ContainerNode or/and EnableSpatialIndex? We'll review if deleted link could remain in their caches.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #9 - Jul 25th, 2025 at 12:56pm
Print Post  
For the main diagram view class we are setting the EnableSpatialIndex flag to true.

And yes we are using the ContainerNode but we are not attaching the child to its collection. We are handling this functionality by our own and the information is stored in the viewmodels.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #10 - Jul 25th, 2025 at 2:27pm
Print Post  
Adding EnableSpatialIndex to test project above is not reproducing, and it already contained containers actually.

Searching for HitTest calls in diagram code, another possibility I can see is the link being found through Selection.Items or diagram.ActiveItem. If you can reproduce reliably, could you verify if these contain the link?

Removed item in selection might happen if deletion command inadvertently changes selection, somehow managing to add the deleted link there. I imagine this might happen either from application's code or by link.Remove itself, if deletion was initiated during mouse events processing where the control could be toggling selection too.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #11 - Jul 28th, 2025 at 9:05am
Print Post  
I couldnt find the link neither in Selection nor in Active item property.

What is the source collection for this HitTest?

From a code point of view I'd say it should only lookup through the Diagram.Items/Links collection...

I managed to fix so its not so urgent.. Smiley
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #12 - Jul 28th, 2025 at 9:42am
Print Post  
Does your application set non-default Diagram.HitTestPriority value, and in response to what events does it run the custom remove command?

Our guess is there's caught-and-ignored exception breaking our invariants somewhere between events, removal code and hit-testing. Since we could not reproduce that, we hoped you'd manage to by copying your diagram config and event code to test project above Wink
  
Back to top
 
IP Logged
 
Patryk
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Jun 13th, 2025
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #13 - Jul 28th, 2025 at 10:13am
Print Post  
Dear Slavcho,

as long as my fix works I will not go deeper in the investigation. If you dont see any weak spots we can put it on hold right now.
Updating the test project would be really complex when keeping in mind the complexity of our solution
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: DiagramLink.MRT(Point, MouseButton) null exception
Reply #14 - Oct 10th, 2025 at 12:13pm
Print Post  
We have debugged a similar scenario for a customer where calling some APIs from delete events was adding link back to spatial index. This build raises the events before removing from index, and should hopefully fix exception above too -

https://www.nuget.org/packages/MindFusion.Diagramming.Wpf/4.2.1-beta1

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint