Well, below is my source, the problem is happening just before opengl star to display something and after the widow is created.
in pseudocode:
start the app in window;
while quit != true
{
check for input
if f1 is pressed
{
delete opengl context
delete window
change resolution
create window
// The error appen around here
create opengl context // Maybe in here
}
}
My source:
void DestroyMainWindow (void)
{
if (WIN_FULLSCREEN)
ChangeDisplaySettings (NULL, CDS_RESET);
if (hRC)
{
if (!wglMakeCurrent (NULL, NULL))
MessageBox (NULL,
"wglMakeCurrent (NULL, NULL)",
"DestroyWindow () Error",
MB_OK | MB_ICONINFORMATION);
if (!wglDeleteContext (hRC))
MessageBox (NULL,
"wglDeleteContext (hRC)",
"DestroyWindow () Error",
MB_OK | MB_ICONINFORMATION);
hRC = NULL;
}
if (hDC && !ReleaseDC (hWnd, hDC))
{
MessageBox (NULL,
"ReleaseDC (hWnd, hDC)",
"DestroyWindow () Error",
MB_OK | MB_ICONINFORMATION);
hDC = NULL;
}
if (hWnd && !DestroyWindow (hWnd))
{
MessageBox (NULL,
"DestroyWindow (hWnd)",
"DestroyWindow () Error",
MB_OK | MB_ICONINFORMATION);
hWnd = NULL;
}
if (!UnregisterClass (WIN_TITLE, hInstance))
{
MessageBox (NULL,
"UnregisterClass (WIN_TITLE, hInstance)",
"DestroyWindow () Error",
MB_OK | MB_ICONINFORMATION);
hInstance = NULL;
}
}
bool CreateMainWindow (void)
{
unsigned int PixelFormat;
WNDCLASS WndClass;
DWORD WinExStyle;
DWORD WinStyle;
RECT WindowRect;
WindowRect.left = 0;
WindowRect.right = WIN_WIDTH;
WindowRect.top = 0;
WindowRect.bottom = WIN_HEIGHT;
hInstance = GetModuleHandle(NULL);
WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
WndClass.lpfnWndProc = (WNDPROC) WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_VERSION6));
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WndClass.hbrBackground = NULL;
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = WIN_TITLE;
if (!RegisterClass (&WndClass))
{
MessageBox (NULL,
"RegisterClass (&WndClass)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
return false;
}
if (WIN_FULLSCREEN)
{
DEVMODE DevMode;
ZeroMemory (&DevMode, sizeof (DevMode));
DevMode.dmSize = sizeof (DevMode);
DevMode.dmPelsWidth = WIN_WIDTH;
DevMode.dmPelsHeight = WIN_HEIGHT;
DevMode.dmBitsPerPel = WIN_GL_COLOR_BITS;
DevMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings (&DevMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
DestroyMainWindow ();
return false;
}
}
if (WIN_FULLSCREEN)
{
WinExStyle = WS_EX_APPWINDOW;
WinStyle = WS_POPUP;
}
else
{
WinExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
WinStyle = WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx (&WindowRect, WinStyle, false, WinExStyle);
if (!(hWnd=CreateWindowEx ( WinExStyle,
WIN_TITLE,
WIN_TITLE,
WinStyle |
WS_CLIPSIBLINGS |
WS_CLIPCHILDREN,
WIN_FULLSCREEN? 0 : WIN_XPOSITION,
WIN_FULLSCREEN? 0 : WIN_YPOSITION,
WindowRect.right - WindowRect.left,
WindowRect.bottom - WindowRect.top,
NULL,
NULL,
hInstance,
NULL)))
{
MessageBox (NULL,
"CreateWindowEx (...)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
DestroyMainWindow ();
return false;
}
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
WIN_GL_COLOR_BITS,
0, 0, 0, 0, 0, 0,
0,
0,
WIN_GL_ACCUM_BITS,
0, 0, 0, 0,
WIN_GL_DEPTH_BITS,
WIN_GL_STENCIL_BITS,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};
if (!(hDC = GetDC (hWnd)))
{
MessageBox (NULL,
"GetDC (hWnd)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
DestroyMainWindow ();
return false;
}
if (!(PixelFormat = ChoosePixelFormat (hDC, &pfd)))
{
MessageBox (NULL,
"ChoosePixelFormat (hDC, &pfd)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
DestroyMainWindow ();
return false;
}
if (!SetPixelFormat (hDC, PixelFormat, &pfd))
{
MessageBox (NULL,
"SetPixelFormat (hDC, PixelFormat, &pfd)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
DestroyMainWindow ();
return false;
}
if (!(hRC = wglCreateContext (hDC)))
{
MessageBox (NULL,
"wglCreateContext (hDC)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
DestroyMainWindow ();
return false;
}
if (!wglMakeCurrent (hDC, hRC))
{
MessageBox (NULL,
"wglMakeCurrent (hDC, hRC)",
"CreateWindow () Error",
MB_OK | MB_ICONEXCLAMATION);
DestroyMainWindow ();
return false;
}
ShowWindow (hWnd, SW_SHOW);
SetForegroundWindow (hWnd);
SetFocus (hWnd);
ResizeMainWindow (WIN_WIDTH, WIN_HEIGHT);
WIN_GL_NEED_INIT = true;
return true;
}