WGL Message:WGL: __wglDDrawSwapBuffersBlit: Blt: DDERROR = DDERR_GENERIC

hi~,all:

i’ve got an app with which i could edit a planar graph. After selecting a Node with the mouse, modify the Node’s coordinate values in a modeless dialog.

But after modify several Nodes as expected :slight_smile: , the view window and the dialog window become fragmentized :confused: . And the debug output window outputs(debug version, i doesn’t run the app in release version):
Warning: Uncaught exception in WindowProc (returning 0).
First-chance exception in Tool.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
WGL Message:WGL: __wglDDrawSwapBuffersBlit: Blt: DDERROR = DDERR_GENERIC

WGL Message:WGL: __wglDDrawSwapBuffersBlit: Blt: DDERROR = DDERR_GENERIC

WGL Message:WGL: __wglDDrawSwapBuffersBlit: Blt: DDERROR = DDERR_GENERIC

WGL Message:WGL: __wglDDrawSwapBuffersBlit: Blt: DDERROR = DDERR_GENERIC

The below are some code pieces supposed to be involved:

void COpenGLView::OnMouseMove(… CPoint point)
{
GLuint nName = 0;
if (select(point, nName))
{
m_nSelName = nName;
…; // hilight the Node named nName.
}
}

void COpenGLView::OnLButtonDblClk(…)
{
m_pModelessDlg->SetSelName(m_nSelName);/m_pModelessDlg’s parent window is the view window./
…; /* valuate the control with the coordinates of Node m_nSelName, so that i can modify the Node.*/
}

void COpenGLView::select(const CPoint& pt, GLuint& nName)
{
CPoint point = pt;
nName = -1;
GLuint* pSelectBuffer = new GLuint[1024];
ASSERT(pSelectBuffer);

// get current matrix status
GLint aiCurrentViewport[4];
glGetIntegerv(GL_VIEWPORT, &aiCurrentViewport[0]);
point.y = aiCurrentViewport[3] - point.y;

// begin select
CDC* pDC = GetDC();
wglMakeCurrent(pDC->GetSafeHdc(), m_hGLContext);
glSelectBuffer(SELECT_BUF_SIZE, pSelectBuffer);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);

// transformation
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(point.x, point.y , 0.1f , 0.1f , &aiCurrentViewport[0]);
glMultMatrixd( &m_adCurrentProjectMatrix[0][0] );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
glLoadMatrixd( &m_adCurrentMoldMatrix[0][0] );

// render for selection
draw4Select();/render all the nodes with gluSphere(m_pQuad, …)/

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode( GL_MODELVIEW );

// decode the selection result
GLint nHits = glRenderMode(GL_RENDER);
GLint nNames;
GLuint* pBuffer = pSelectBuffer;
…;
…;
if (pSelectBuffer) delete []pSelectBuffer;

return (nName!=-1);
}

oh~ , the platform: Window2K, msdev 6.0, nvidia card.
Any idea will be deeply appreciated!!

Is SELECT_BUF_SIZE == 1024?
Change GLuint* pSelectBuffer = new GLuint[1024];
to GLuint* pSelectBuffer = new GLuint[SELECT_BUF_SIZE];

Other than that, a DirectDraw errors from SwapBuffers look like you’re using a Microsoft pixelformat.
Check the glGetString(GL_VENDOR) and GL_RENDERER to see if you’re actually using a hardware accelerated pixelformat.
If it doesn’t say NVIDIA, analyze your pixelformat selection.
If that doesn’t help, reinstall and/or update your display drivers.

Relic, thanks a lot for patient reply!

But about your first advice, i don’t think it’s the problem. In fact, there is a sentence as
#define SELECT_BUF_SIZE 1024
and i just rewrite the code as in my post for convenience.

The app uses Microsoft pixelformat indeed, and my platform is Win2K, Visual C++6.0.

As for your second advice, i’ll try it.

hi,

glGetString(GL_VENDOR) == “NVIDIA Corporation” and glGetString(GL_RENDERER) == “GeForce2 MX/PCI/SSE2”;

glGetString(GL_VERSION) == “1.4.0” and glGetString(GL_EXTENSIONS) == “GL_ARB_imaging GL_ARB_multitexture GL_ARB_point_parameters GL_ARB_texture_compression GL_ARB_texture_cube_map GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_dot3 GL_ARB_texture_mirrored_repeat GL_ARB_transpose_matrix GL_ARB_vertex”;

And the pixel format i used is as follow:

pixelDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER | PFD_STEREO_DONTCARE;
pixelDesc.iPixelType = PFD_TYPE_RGBA;
pixelDesc.cColorBits = 32;
pixelDesc.cRedBits = 8;
pixelDesc.cRedShift = 16;
pixelDesc.cGreenBits = 8;
pixelDesc.cGreenShift = 8;
pixelDesc.cBlueBits = 8;
pixelDesc.cBlueShift = 0;
pixelDesc.cAlphaBits = 0;
pixelDesc.cAlphaShift = 0;
pixelDesc.cAccumBits = 64;
pixelDesc.cAccumRedBits = 16;
pixelDesc.cAccumGreenBits = 16;
pixelDesc.cAccumBlueBits = 16;
pixelDesc.cAccumAlphaBits = 0;
pixelDesc.cDepthBits = 32;
pixelDesc.cStencilBits = 8;
pixelDesc.cAuxBuffers = 0;
pixelDesc.iLayerType = PFD_MAIN_PLANE;
pixelDesc.bReserved = 0;
pixelDesc.dwLayerMask = 0;
pixelDesc.dwVisibleMask = 0;
pixelDesc.dwDamageMask = 0;

And ChoosePixelFormat(hDC,&pixelDesc) == 9.

Is there anything wrong???

hi~~, all,

:smiley: I delete the following sentence
wglMakeCurrent(pDC->GetSafeHdc(), m_hGLContext);
from COpenGLView::select(),
and the problem seems to be solved. Because i continue to edit for a long time, the app works properly.

:confused: It’s amazing, and i am confused.
I use wglMakeCurrent() in COpenGLView::OnPaint(), and if i didn’t edit which means never to call COpenGLView::select(), the app works well.
So i am thinking that there must be something different in the function COpenGLView::select() from COpenGLView::OnPaint() when calling wglMakeCurrent(). But what is that??? :confused:

You need to call ReleaseDC with the CDC pointer. When you don’t do this you will get problems like the one you describe.

Matt