ThinkGeo.com    |     Documentation    |     Premium Support

ZoomIntoCenter leads to TargetInvocationException for large values

Hi,


If I zoom in my some large percentage, say 96%, I get a TargetInvocationException.  The CurrentScale is set to 44997469.7142857 when I apply the zoom.  


When I zoom in by smaller percentages, like 30% and allow the map to repaint each time,  I don't get the exception.  However, I need to zoom into some reasonable scale level without it crashing, when the map is zoomed way out. 


The inner exception says "Parameter is not valid", but it doesn't say what parameter.  


This makes me think that during repaint, your map code is updating some state or variable.


Here is the stack:


   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

   at System.Delegate.DynamicInvokeImpl(Object[] args)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.DispatcherOperation.InvokeImpl()

   at System.Threading.ExecutionContext.runTryCode(Object userData)

   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

   at System.Threading.ExecutionContext.Run(ExecutionContext 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, Boolean isSingleParameter)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

   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.TranslateAndDispatchMessage(MSG& msg)

   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

   at System.Windows.Application.RunInternal(Window window)

   at com.wsi.common.main.App.Main() in C:\Users\gshaffer\Documents\src\central\client\main\obj\Debug\App.g.cs:line 50

   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadHelper.ThreadStart()


Please Help!


Thanks,


Greg



Greg,


I have tried to build a simple sample to recreate your problem but I can not make it. I think maybe there is something I misunderstand, so please review my sample code and modify it to make it can recreate your problem.


Thanks


James



1851-ZoomInCenterTest.zip (8.65 KB)

Thanks James.  I will look at your example in the morning.


I managed to get more info out of the exception.  You can see some ThinkGeo code at the bottom:


System.Reflection.TargetInvocationException was unhandled

  Message="Exception has been thrown by the target of an invocation."

  Source="mscorlib"

  StackTrace:

       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

       at System.Delegate.DynamicInvokeImpl(Object[] args)

       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.DispatcherOperation.InvokeImpl()

       at System.Threading.ExecutionContext.runTryCode(Object userData)

       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

       at System.Threading.ExecutionContext.Run(ExecutionContext 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, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

       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.TranslateAndDispatchMessage(MSG& msg)

       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

       at System.Windows.Application.RunInternal(Window window)

       at com.wsi.common.main.App.Main() in C:\Users\gshaffer\Documents\src\central\client\main\obj\Debug\App.g.cs:line 50

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

  InnerException: System.ArgumentException

       Message="Parameter is not valid."

       Source="System.Drawing"

       StackTrace:

            at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)

            at ThinkGeo.MapSuite.DesktopEdition.WpfMap.xfbd15a0e9d15f4e2(Graphics x783a718028818269, RectangleShape xb35a33b423b17f65)

            at ThinkGeo.MapSuite.DesktopEdition.WpfMap.x7d52d0ad1d6779cd(Boolean x991dc8ddc7528b44, RectangleShape x178b193eec228e6e)

       InnerException: 



Greg, 
  
 I have done some deeper research that I found you’re on MultiThreaded mode, so I update my sample code to set it to MultiThreaded too, but I still can not recreate your problem. 
  
 As I know, we have fixed some bugs for multi threaded mode after 3.1.299, so could you download the latest version and try it again, you can find the package from helpdesk.thinkgeo.com 
  
 Please let me know you test result. 
  
 Thanks 
  
 James

Hi James, 
  
 I downloaded DesktopEditionFull3.1.412.0DllPackage from my customer portal and I no longer see the error.  In addition, I noticed that the pan performance is much smoother.  And, I noticed that smoothing has been turned off, which is ok if it leads to better performance.  However, my black background is now white.  Perhaps I need to download a full version for the background to work properly?  But, I didn’t see a full download there. Do  I need to contact Moritz? 
  
 Thanks, 
 Greg

Greg,


Thanks for your feedback.
 
I think the reason for the white background is that you did not set it, try to set the background as following way, hope it helps.

winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Hi Yale,


We are indeed setting the background color.  The only change we made was add the latest 4 dev dlls to our lib directory.  Is there something else we need to do instead?  When we back out the updated dlls, the color starts working again.


Here's what I'm seeing.  When I first display our map, the background is white.  There is no "unlicensed version" text being displayed or anything like that, so I think it recognizes that I have a valid license installed.  Then, when I use one of the TrackOverlay modes, the background color of my map somehow gets rendered properly.


So, I subscribed to the BackgroundOverlay.Drawn event, restarted, and I noticed that the BackgroundOverlay.Drawn event isn't getting raised when I initially start the application.  Do I now need to tell it to initially repaint?  It repaints once I use the TrackOverlay mode.


Thanks,


Greg


 



Greg, 
  
 Thanks for your post. 
  
 Here I jumped out to say something about the event Drwing and Drawn hooked up in the BackgroundOverlay and AdormentOverlay. 
  
 These two events will only be fired at the overlay real drawn time, for example, the first time to load the map control or when you resize the map control. If you only pan or zoom in & zoom out, these events will not happen because we just use the cached bitmap for the BackgroundOverlay and AdormentOverlay at that time, the real drawing is not happening in behind. 
  
 About the other problem, I left it to James who will do more investigations about it. Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale 


Greg, 
  
 Do you use the “ZoomInCenterTest” sample which I attached? I can not recreate your problem by testing it, If I set Singlethreaded mode, both 3.1.299 and 3.1.412 can work; if I set Multithreaded mode, both of them can not work. It’s a problem that I will try to fix it but I think it’s not exact match your description, you said the old version can work but the 3.1.412 can’t. If you update the sample code or you use another sample, please provide it and I can test to find the exact problem. 
  
 If I got something I will let you know. 
  
 Thanks 
 James

Greg,


I did some more investigatation and I found the reason of my sample's problem. If you want to display the current back ground you need to set the right MapUnit and CurrentExtent, another important thing is your map must add at least one overlay to Overlays, such as


            wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
            wpfMap1.CurrentExtent = new RectangleShape(-133.2515625, 89.2484375, 126.9046875, -88.290625);
            wpfMap1.Overlays.Add(new WorldMapKitWmsDesktopOverlay());

Thanks


James