OpenGL抑制基于MFC对话框的应用程序中的异常 [英] OpenGL suppresses exceptions in MFC dialog-based application

查看:202
本文介绍了OpenGL抑制基于MFC对话框的应用程序中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MSVS2005创建的基于MFC驱动的基于对话框的应用程序。这是我的问题一步一步。我的对话框上有按钮和相应的点击处理程序,代码如下:

  int * i = 0; 
* i = 3;

我正在运行调试版本的程序,当我点击按钮时,Visual Studio抓住焦点,警报访问冲突写入位置异常,程序无法从错误中恢复,我所能做的就是停止调试。这是正确的行为。



现在我在 OnInitDialog()方法中添加一些OpenGL初始化代码: / p>

  HDC DC = GetDC(GetSafeHwnd()); 
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),//此pfd的大小
1,//版本号
PFD_DRAW_TO_WINDOW | //支持窗口
PFD_SUPPORT_OPENGL | //支持OpenGL
PFD_DOUBLEBUFFER,//双缓冲
PFD_TYPE_RGBA,// RGBA类型
24,// 24位颜色深度
0,0,0,0,0 ,0,// color bits ignored
0,// no alpha buffer
0,// shift bit ignored
0,// no accumulation buffer
0,0,0 ,0,// accum bits ignored
32,// 32-bit z-buffer
0,// no stencil buffer
0,// no辅助缓冲区
PFD_MAIN_PLANE, // main layer
0,//保留
0,0,0 //层屏蔽忽略
};

int pixelformat = ChoosePixelFormat(DC,& pfd);
SetPixelFormat(DC,pixelformat,& pfd);

HGLRC hrc = wglCreateContext(DC);
ASSERT(hrc!= NULL);
wglMakeCurrent(DC,hrc);

当然这不完全是我做的,这是我的代码的简化版本。现在奇怪的事情开始发生:所有的初始化都很好,在$ code> OnInitDialog()中没有错误,但是当我点击按钮...没有异常抛出。什么都没发生。在所有如果我在 * i = 3; 上设置一个断点,然后按F11,则处理程序函数立即停止,并将焦点返回到应用程序,该应用程序继续工作得很好我可以再次点击按钮,同样的事情会发生。



似乎有人处理发生的访问冲突异常,并将执行静默地返回到主应用程序消息接收周期。



如果我注释行 wglMakeCurrent(DC,hrc); ,都可以像以前一样正常工作,抛出异常,Visual Studio抓住它并显示带有错误消息的窗口,程序必须先被终止。



在Windows 7 64位下,我遇到这个问题,NVIDIA GeForce 8800具有最新的驱动程序(11.01.2010),可在网站上安装。我的同事有Windows Vista 32位,没有这样的问题 - 异常被抛出,应用程序崩溃在这两种情况下。



嗯,希望好家伙会帮助我: / p>

PS最初发生在这个主题。

解决方案

好的,我发现了一些关于这个的更多信息。在我的情况下,Windows 7将安装 KiUserCallbackExceptionHandler 作为异常处理程序,在调用我的WndProc并给我执行控制之前。这是由 ntdll!KiUserCallbackDispatcher 完成的。我怀疑这是Microsoft采取的防止黑客入侵SEH的安全措施。



解决方案是将wndproc(或hookproc)与try / except框架包起来您可以在Windows之前捕获异常。



感谢Skywing在 http://www.nynaeve.net/


我们已经联系了nVidia这个
问题,但他们说这不是他们的
错误,而是微软的。可以
你可以告诉你如何找到
异常处理程序?你有没有
一些额外的信息,例如微软的一些
反馈?


我使用WinDbg中的!exchain命令来获取这些信息。 p>

I have an MFC-driven dialog-based application created with MSVS2005. Here is my problem step by step. I have button on my dialog and corresponding click-handler with code like this:

int* i = 0;
*i = 3;

I'm running debug version of program and when I click on the button, Visual Studio catches focus and alerts "Access violation writing location" exception, program cannot recover from the error and all I can do is to stop debugging. And this is the right behavior.

Now I add some OpenGL initialization code in the OnInitDialog() method:

    HDC DC = GetDC(GetSafeHwnd());
    static PIXELFORMATDESCRIPTOR pfd =
    {
      sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
      1, // version number
      PFD_DRAW_TO_WINDOW | // support window
      PFD_SUPPORT_OPENGL | // support OpenGL
      PFD_DOUBLEBUFFER, // double buffered
      PFD_TYPE_RGBA, // RGBA type
      24, // 24-bit color depth
      0, 0, 0, 0, 0, 0, // color bits ignored
      0, // no alpha buffer
      0, // shift bit ignored
      0, // no accumulation buffer
      0, 0, 0, 0, // accum bits ignored
      32, // 32-bit z-buffer
      0, // no stencil buffer
      0, // no auxiliary buffer
      PFD_MAIN_PLANE, // main layer
      0, // reserved
      0, 0, 0 // layer masks ignored
    };

    int pixelformat = ChoosePixelFormat(DC, &pfd);
    SetPixelFormat(DC, pixelformat, &pfd);

    HGLRC hrc = wglCreateContext(DC);
    ASSERT(hrc != NULL);
    wglMakeCurrent(DC, hrc);

Of course this is not exactly what I do, it is the simplified version of my code. Well now the strange things begin to happen: all initialization is fine, there are no errors in OnInitDialog(), but when I click the button... no exception is thrown. Nothing happens. At all. If I set a break-point at the *i = 3; and press F11 on it, the handler-function halts immediately and focus is returned to the application, which continue to work well. I can click button again and the same thing will happen.

It seems like someone had handled occurred exception of access violation and silently returned execution into main application message-receiving cycle.

If I comment the line wglMakeCurrent(DC, hrc);, all works fine as before, exception is thrown and Visual Studio catches it and shows window with error message and program must be terminated afterwards.

I experience this problem under Windows 7 64-bit, NVIDIA GeForce 8800 with latest drivers (of 11.01.2010) available at website installed. My colleague has Windows Vista 32-bit and has no such problem - exception is thrown and application crashes in both cases.

Well, hope good guys will help me :)

PS The problem originally where posted under this topic.

解决方案

Ok, I found out some more information about this. In my case it's windows 7 that installs KiUserCallbackExceptionHandler as exception handler, before calling my WndProc and giving me execution control. This is done by ntdll!KiUserCallbackDispatcher. I suspect that this is a security measure taken by Microsoft to prevent hacking into SEH.

The solution is to wrap your wndproc (or hookproc) with a try/except frame so you can catch the exception before Windows does.

Thanks to Skywing at http://www.nynaeve.net/

We've contacted nVidia about this issue, but they say it's not their bug, but rather the Microsoft's. Could you please tell how you located the exception handler? And do you have some additional information, e.g. some feedbacks from Microsoft?

I used the "!exchain"-command in WinDbg to get this information.

这篇关于OpenGL抑制基于MFC对话框的应用程序中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆