jeremytammik / RevitLookup

Interactive Revit RFA and RVT project database exploration tool to view and navigate BIM element parameters, properties and relationships.
http://thebuildingcoder.typepad.com
MIT License
1.03k stars 294 forks source link

Fatal Error - Null Exception #180

Closed ricaun closed 7 months ago

ricaun commented 1 year ago

I found a Null Exception, only test in Revit 2024 with the last release 2024.0.8.

Steps:

Here is a video on how to do it: https://youtu.be/Exx5ra3Keqc

I get the exception below by opening Revit with debug: https://youtu.be/ICqYxJd7UH0

image

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null.
Parameter name: element
  Source=PresentationCore
  StackTrace:
   at MS.Internal.Media.VisualTreeUtils.AsNonNullVisual(DependencyObject element, Visual& visual, Visual3D& visual3D)
   at System.Windows.Media.VisualTreeHelper.GetChild(DependencyObject reference, Int32 childIndex)
   at RevitLookup.Views.Utils.VisualUtils.GetTreeViewItem(ItemsControl container, Int32 index)
   at RevitLookup.Views.Pages.SnoopViewBase.<OnTreeSourceChanged>d__17.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   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 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   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()
Nice3point commented 1 year ago

Unable to reproduce this issue https://github.com/jeremytammik/RevitLookup/assets/20504884/a79e9266-864f-4a79-8312-c10e8e1cfccf

@ricaun If you can, run the project in Debug mode and provide the name of the class, line number and method where the exception is thrown. You only show Revit in the video and I don't see VS there 🙈

ricaun commented 1 year ago

Unable to reproduce this issue https://github.com/jeremytammik/RevitLookup/assets/20504884/a79e9266-864f-4a79-8312-c10e8e1cfccf

@ricaun If you can, run the project in Debug mode and provide the name of the class, line number and method where the exception is thrown. You only show Revit in the video and I don't see VS there 🙈

I was not running the RevitLookup project so that's why I didn't show the line... Is something with the Revit Lookup Snoop Summary and then Snoop Active Document Gonna download and debug the RevitLookup project to check what is happening...

ricaun commented 1 year ago

itemsPresenter is null

https://github.com/jeremytammik/RevitLookup/blob/839852d3db39f2fb33a5bdf297acd9627dc72c0a/RevitLookup/Views/Utils/VisualUtils.cs#L102C1-L102C100

image

Nice3point commented 1 year ago

It's strange why item presenter doesn't find it. I'll take a closer look later)

ricaun commented 1 year ago

I added.

if (itemsPresenter is null) return null;

Before line 102, kinda fixed.

Maybe my machine is slow or something... https://youtu.be/L74qMwW-QA8

Nice3point commented 1 year ago

It's more of a crutch, we need to find a more natural reason

ricaun commented 1 year ago

I guess I found it! Disable smooth! (in your video smooth is enable)

With Smooth disabled, the TransitionDuration is zero and in my machine, the FindVisualChild makes itemsPresenter to be null.

With Smooth enables itemsPresenter is found normally.

ricaun commented 1 year ago

The null happens when you open the RevitLookup - Dashboard and click on the Snoop summary that is empty and then try to snoop an Active document.

Nice3point commented 1 year ago

@ricaun I found the reason is that apparently the method is called twice. Here we need to either add one unsubscribe or change the logic and rewrite TreeSourceChanged. I will try to fix it this week

Thanks Luiz for raising it 😉

изображение

ricaun commented 1 year ago

No problem 🤘


Now about another subject:

I was testing some way to another plugin to call the snoop navigation method to open the RevitLookup UI with any object. I manage to make work using reflection and looks like the SnoopService does not allow me to snoop class that is not from Revit or something.

Probably makes more sense to create a Discussion for this.