当我碰到鼠标滚轮时,我的WPF应用程序有时会崩溃,并出现OverflowException.这是堆栈跟踪的开始:
at System.Windows.Shell.WindowChromeWorker._HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, Boolean& handled)
Run Code Online (Sandbox Code Playgroud)
从那以后,我将它追溯到WindowChrome - 我甚至可以用WindowChrome重现它.但它似乎必须全屏.这里发生了什么?有解决方法吗?
这实际上是堆栈跟踪指向的类中的一个问题.微软有一个错误WindowChromeWorker,表现在一个OverflowException.
我只是用罗技鼠标观察到这一点,但从我在其他地方看到的情况来看,它可能会发生在其他老鼠身上.
唯一可用的解决方法是禁止全屏,并阻止用户发送包含侧滚信息的消息.
我的想法是这样的:
//Overflow gets inlined to here. (In System.Windows.Shell.WindowChromeWorker.cs)
var mousePosScreen = new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam));
//Which calls this (In Standard.Utility)
public static int GET_X_LPARAM(IntPtr lParam)
{
return LOWORD(lParam.ToInt32());
}
//Unsafe cast and overflow happens here (In System.IntPtr)
public unsafe int ToInt32() {
#if WIN32
return (int)m_value;
#else
long l = (long)m_value;
return checked((int)l); //Overflow actually occurs and is thrown from here.
#endif
}
Run Code Online (Sandbox Code Playgroud)
似乎是一个糟糕的假设,Standard.Utility因为lParams始终适合32位,并且一些鼠标驱动程序通过在那里写入而违反64位系统上的那些.
参考源WindowChromeWorker是在这里.
| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |