Thread: When programs close with no warning

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    36

    When programs close with no warning

    I can understand when applications close with an error report when I have memory leaks or try to access memory that isn't for me, but I cannot understand why they would close with no warning at all.

    It leaves me clueless as to what causes it. When a program crashes without an error report, what does that indicate? I have never exepreinced this before...

  2. #2
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    I had that problem several minutes ago myself, it happened when I carelessly copy&paste'd a code and did some modifications and ended up with an infinite for loop, like

    Code:
    for (i = 10; i > 0; i++)
    this caused my program to quit without any error message. I narrowed down the problematic line by placing debug messages (printf) in the code and running from the console, checking how far the code would run. A more sophisticated method would be to add breakpoints and run your program in debug mode.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    36
    I have one 'infinite' loop in my app. One that calls the main routine and when the routine returns, it then calls a process message function which is just a PeekMessage.

    I know why it closes now, but damn if I know why...

    The PeekMessage for some reason is picking up WM_QUIT from the message queue(!?). I didn't press the close button, AltF4 or anything that normally closes it. It just somehow pops into the message queue. I have no funciton in my app that places WM_QUIT into the message loop excpet ofcourse DefWindowProc and the WM_DESTROY handler.

    My peek message function looks like:

    Code:
    int ProcessMsg(void)
    {
    	MSG msg;
    	PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
    
    	if(!(msg.message == WM_QUIT))
    	{
    		TranslateMessage(&msg); 
    		DispatchMessage(&msg);
    
    		return 1;
    	}
    	return 0;
    }
    Where a return of 0 will have it return from main. This leaves my wondering what special occurence will cause WM_QUIT to appear in the queue...
    Last edited by Gerread; 03-24-2007 at 09:16 PM.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I have never seen an app randomly get WM_QUIT posted....


    Are you sure it is getting the WM_QUIT and not crashing in some other location?

    Are any of the child windows getting a WM_QUIT, as you have not specified the HWND in the PeekMessage()?

    Many apps crash without an error report so do not use that to definativly state that the app is closing due to a WM_QUIT.

    Place a breakpoint on the 'return 0' or send a TRACE() or to a log file to be sure it is getting a WM_QUIT.

    I also find

    if(msg.message != WM_QUIT)

    easier to read than

    if(!(msg.message == WM_QUIT))
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM