ZoomAdorner crashes WPF application

Greetings,

I’ve written a simple application in WPF to test the cameras we are using. It’s basically a few GUI elements to select a camera, open it and start the stream, and the cvb:Display element to show the stream.
But the application crashes with a NullReferenceException when using the “+” or “-” buttons on the ZoomAdorner of the display, unless the display size is changed or the CTRL+mouse wheel zoom is used before using the ZoomAdorner buttons.

System.NullReferenceException
HResult=0x80004003
Message=Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
Source=Stemmer.Cvb.Wpf
StackTrace:
at Stemmer.Cvb.Wpf.Adorners.ZoomAdornerContent.IncreaseZoomButton_Click(Object sender, RoutedEventArgs e)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonDown(MouseButtonEventArgs e)
at System.Windows.Controls.Primitives.RepeatButton.OnMouseLeftButtonDown(MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(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.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at CameraCalibrationTool.App.Main()

Am I missing anything to initialize the ZoomAdorner or the Display element or is it broken?

Regards,
Jens

Hi @j.wilhelm

which version of :cvb: are you using exactly?

I just checked with 13.04.002 and found it to be workin (I simply hacked the WpfGenICam example to load “Clara.bmp” and assign it by changing line 117 to 119 in MainWindow.xaml to

      <Border Grid.Column="0" Style="{StaticResource DisplayBorderStyle}">
        <cvb:Display x:Name="display" IsZoomAdornerVisible="True"/>
      </Border>

and modifying the ctor of MainWindow to

    public MainWindow()
    {
      InitializeComponent();
      var clara = Image.FromFile(@"%CVB%\Tutorial\Clara.bmp");
      display.Image = clara;
    }

This works on my system. If your version is at least 13.04.001, can you please try this modification and let me know if it works for you? If your version is 13.04.000 or older then an update might help: In 13.04.001 we fixed an inconsistency in zoom step calculation that might be the culprit here… (the zoom sequence was calculated in a way that could - with large images - lead to a huge jump in zoom center and zoom factor when moving from the initial StretchZoomFactor to the next selected one which could lead to an invalid reference being set during the dependency property updates.

I’m using the version from the latest installer. The installer states 13.04.002, although the Stemmer.Cvb.dll states 13.04.0.0. File version is 1.112.1.737.
But I upgraded from 13.02.002, so 13.04.000 was never installed on the system.

I tested your code, also with a camera stream, and this works. But only as long as the display image is assigned in the MainWindow cunstroctor.
If the assignment is done in a button click event method for example, it still creates the NullReferenceException when using the ZoomAdorner.

Hi!

Thank you for the additional information! I can confirm what you describe - I think I’ll have a fix for that by tomorrow evening. (it’s not hugely complicated, but there is a problematic path in the hand-over of the precalculated zoom levels to the slider in the ZoomAdorner that can lead to the Ticks collection of the zoom adorner being null - and that what raises the exception).

That sounds fantastic!
Thank you for taking care of it so fast.

:slight_smile:
please give the attached DLL a shot: Stemmer.Cvb.Wpf.dll.zip (107.1 KB)
The zip archive contains version 1.112.3.746 of the Stemmer.Cvb.Wpf.dll which contains the ZoomAdorner. The DLL has assembly version 1.112.0.0 and is therefore compatible with :cvb: 13.04.xxx. As no interface changes were necessary, it is basically drop-in-compatible.

However, “drop-in” in this context means that you’ll need to install this version in the global assembly cache. To do this, unzip the DLL from this file to a location of your choice, then open a Visual Studio command prompt with admin privileges and navigate to the folder where you places the Stemmer.Cvb.Wpf.dll from the zip archive and enter the following command:

gacutil -i Stemmer.Cvb.Wpf.dll

The tool should confirm the successful installation of the DLL in the GAC and you can now use it in your software. I recommend to also replace the same DLL in %CVB%\Lib\Net - just to avoid confusion (this step isn’t strictly necessary as the .Net runtime will prioritize the GAC-installed one in the dependency resolution - but you never know…).

The fixed DLL will be part of the upcoming patch release 13.04.003 (early next week…).

1 Like

Thanks again, the new DLL works and fixes the problem.

1 Like

Great to know - thanks for the feedback! :slight_smile: