🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

System Resources

Started by
3 comments, last by acw83 24 years, 5 months ago
Everytime I run my program, then exit, the total system''s resources drops by 2%. Is this normal? Is it a leak? Here is my source that is causing the 2% loss. PLEASE HTML LEAVE MY CODE ALONE... ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // // // NAME: WinGL.cpp // // // // DESC: A basic tempalte for Windows fullscreen // // OpenGL. // // // // AUTH: Andrew C. White // // // // DATE: January 17, 2000 // // // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// //============================================================ // Includes //============================================================ #include "stdafx.h" //============================================================ // Defines //============================================================ #define NAME "WinGL" #define WIDTH 800 #define HEIGHT 600 #define BPP 32 //============================================================ // Globals //============================================================ static HWND hWnd =NULL; // Used for Windows static HDC hDC =NULL; // Used for GDI and OpenGL static HGLRC hRC =NULL; // Used for OpenGL static BOOL AppRunning =TRUE; // Exit flag static int OldDisplayModeX =NULL; // Restore previous display static int OldDisplayModeY =NULL; // Restore previous display //============================================================ // Functions //============================================================ void Initialize(void); void Main(void); void Shutdown(void); void ExitOnError(HWND hWnd, LPSTR szError); //============================= // Initialize // Initialization application code. //============================= void Initialize(void) { hDC = GetDC(hWnd); if( !hDC ) ExitOnError(hWnd, "Error calling GetDC!"); static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW / PFD_SUPPORT_OPENGL / PFD_DOUBLEBUFFER, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0 ,0 ,0 }; SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); glViewport(0, 0, WIDTH, HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0f, (GLfloat)WIDTH / (GLfloat)HEIGHT, 1.0f, 400.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); GLfloat diffuselight[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuselight); GLfloat ambientlight[] = { 0.01f, 0.01f, 0.01f, 1.0f }; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientlight); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); return; } //============================= // Main // Main application code. //============================= void Main(void) { static GLfloat angle = 0; if( angle == 360 ) angle = 0; glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT); glShadeModel(GL_SMOOTH); GLfloat lightpos[] = { 0.0f, 0.0f, 100.0f, 0.0f }; glLightfv(GL_LIGHT0, GL_POSITION, lightpos); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -100.0f); glColor3f(0.0f, 0.0f, 1.0f); glutSolidSphere(10.0f, 30, 30); GLfloat lightpos2[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION, lightpos2); glColor3f(1.0f, 1.0f, 0.0f); glPushMatrix(); glRotatef(angle, 0.0f, 0.3f, 0.1f); glTranslatef(50.0f, 0.0f, 0.0f); glutSolidSphere(5.0f, 30, 30); glPopMatrix(); SwapBuffers(hDC); angle += 2.5f; return; } //============================= // Shutdown // Shutdown the app. //============================= void Shutdown(void) { wglMakeCurrent(NULL, hRC); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); DEVMODE devMode; memset( &devMode, 0, sizeof( devMode ) ); devMode.dmSize = sizeof( devMode ); devMode.dmPelsWidth = OldDisplayModeX; devMode.dmPelsHeight = OldDisplayModeY; devMode.dmFields = DM_PELSWIDTH / DM_PELSHEIGHT; ChangeDisplaySettings( &devMode, CDS_FULLSCREEN ); return; } //============================= // ExitOnError // Displays message box with error and closes. //============================= void ExitOnError(HWND hWnd, LPSTR szError) { ShowCursor(TRUE); MessageBox(hWnd, szError, "Error", MB_OK); AppRunning = FALSE; return; } //============================= // WndProc // Window message handler. //============================= LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_KEYDOWN: // Process keyboard input. { switch((int) wParam) { case VK_ESCAPE: { AppRunning = FALSE; } break; default: break; } return(0); } break; } return (DefWindowProc(hWnd, message, wParam, lParam)); } //============================= // WinMain // The entry point, and main loop. //============================= int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { OldDisplayModeX = GetSystemMetrics(SM_CXSCREEN); OldDisplayModeY = GetSystemMetrics(SM_CYSCREEN); DEVMODE devMode; memset( &devMode, 0, sizeof( devMode ) ); devMode.dmSize = sizeof( devMode ); devMode.dmPelsWidth = WIDTH; devMode.dmPelsHeight = HEIGHT; devMode.dmFields = DM_PELSWIDTH / DM_PELSHEIGHT; ChangeDisplaySettings( &devMode, CDS_FULLSCREEN ); WNDCLASSEX winclass = { sizeof(winclass), CS_OWNDC / CS_HREDRAW / CS_VREDRAW, WndProc, NULL, NULL, hInstance, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH) GetStockObject(BLACK_BRUSH), NULL, "winclass", LoadIcon(NULL, IDI_APPLICATION) }; RegisterClassEx(&winclass); hWnd = CreateWindowEx(WS_EX_TOPMOST, "winclass", NAME, WS_POPUP / WS_CLIPCHILDREN / WS_CLIPSIBLINGS, 0, 0, WIDTH, HEIGHT, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); MSG message; Initialize(); while(AppRunning) { if( PeekMessage(&message, hWnd, 0, 0, PM_REMOVE) ) { TranslateMessage(&message); DispatchMessage(&message); } Main(); } Shutdown(); return (0); }
Advertisement
Well, I glanced through your code for you, but I don''t see anything glaringly wrong. In fact, about the only thing I noticed was how you are exiting your application by just breaking the message pump and not using the WM_DESTROY message and the PostQuitMessage(0) function, but I am not sure how this could cause a leak.

Sorry, I tried.
I-Shaolin was absolutely right. Glancing at the codes, I *NEVER* see the window you''re using being destroyed. And being no PostQuitMessage, your application is still running in the background!
*Try Ctrl-Alt-Del to see if you can see your application name still there*
I quote from Microsoft''s documentation:

"Your WinMain should initialize the application, display its main window, and enter a message retrieval-and-dispatch loop that is the top-level control structure for the remainder of the application’s execution. Terminate the message loop when it receives a WM_QUIT message. At that point, your WinMain should exit the application, returning the value passed in the WM_QUIT message’s wParam parameter. If WM_QUIT was received as a result of calling PostQuitMessage, the value of wParam is the value of the PostQuitMessage function’s nExitCode parameter."

Thus there is in fact apparently no need to use PostQuitMessage, letting the WinMain function run to its end (as he does) should be fine.

Regards

Starfall
try to run it in the debug mode, and you will probably see if there is a memory leak.

hope that will help!

cyberg
cyberg- cyberg_coder@hotmail.com- http://members.xoom.com/cybergsoft

This topic is closed to new replies.

Advertisement