Thread: Unhandled exception

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    Unhandled exception

    When I debug my app there is no problem not even a warning. When I release the app again no warnings no issues while running the program.

    When I run the app manually (double click on the actual icon)
    Code:
    An unhandled win32 exception occurred in ProgX.exe
    It offers me to debug the app again. The app stops in WM_CREATE message. I suppose there might be lack of memory for the program but why does this happen only when I launch it manually?

    Has this ever happened to you. Do you have an Idea what to do next?

    I will certainly provide more information according to what you need to know about the app.

    Thank you in advance for any help

  2. #2
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Does the same also happen when you double-click on executable when it's compiled as a debug build? Try commenting out stuff, or using a bunch of calls to MessageBox() to triangulate on what exact line it's happening on.
    It has never happened to me before, but I'd guess the difference lies in the environment the executable is run in.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Post the code that you have in your WM_CREATE case.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    The debug built works fine if run manually. No prob with that one either. Only with the release.

    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            switch(message)
            {
    		case WM_CREATE:
    			ProgStart(hWnd);
    			_pGame->Clean(hWnd);
    			break;
            }
    }
    ProgStart(hWnd); Contains the following code void Sudoku::Start(HWND hWnd) where does the issue show up.

    If it helps the actual point where the prog stops is in the highlighted line.

    Code:
    void Sudoku::Start(HWND hWnd)
    {
    	// All rects needed to be disabled after start
    	for(int i = 0; i <= m_iRowCount; i++)
    	{
    		for(int j = 0; j <= m_iColCount; j++)
    		{
    			m_bOwner[i][j] = true;
    			m_bActive[i][j] = false;
    			m_bSolver[i][j] = false;
    			bHighLightOwner = false;
    			bHighLightSolver = false;
    			bHighLightBase = false;
    			m_iValue[i][j] = -1;
    			m_iCorrect[i][j] = -1;
    			for(int k = 0; k <= 8; k++)
    			{
    				m_iPossible[i][j][k] = k + 1; // At this point an unhandeled exception always occurs
    			}
    			iProgressBar++;
    			m_bActive[i][j] = false;
    		}
    	}
    }
    All needed variables are declared so I dont believe there is a problem with invalid pointers.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The problem is that you do a buffer overrun (or buffer underrun) somewhere.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    For instance, if m_iRowCount or m_iColCount are 9 -- which would make sense, since that's how many rows and columns there are -- then i and j go over the limit.

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by tabstop View Post
    For instance, if m_iRowCount or m_iColCount are 9 -- which would make sense, since that's how many rows and columns there are -- then i and j go over the limit.
    Quote Originally Posted by Elysia View Post
    The problem is that you do a buffer overrun (or buffer underrun) somewhere.
    There might be a possibility of buffer overrun but why does it work properly in debug build and even while running the release built from the compiller?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Gordon View Post
    There might be a possibility of buffer overrun but why does it work properly in debug build and even while running the release built from the compiller?
    Because you are running into "undefined behaviour" land - it does different things at different times. Like my analogy of running a red-light at a street-crossing: sometimes you get across no problem. Sometimes you get beeped at, sometimes you get hit by a car coming the other way. It's not predictable, because you are doing things that aren't supposed to be done.

    The parameters for your application will be different depending on the way that your application is started - environment variables are different, some other stuff may well be different too.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I suppose you are using VS, yes?
    Then let me throw in a debug advice for you.
    Goto breakpoints, add and data breakpoint. Set 3 different breakpoints, one for i, j, and k separately. Set the location to the variable (eg &i). Set the condition to a boolean expression of values that are out-of-range, or values that would cause you to access elements outside the array.
    So if the array was defined as myarray[10][10][10], then set breakpoints for:
    - &i, i < 0 || i > 9
    - &j, j < 0 || j > 9
    - &k, k < 0 || k > 9

    If done properly, VS will then break when these conditions are true. In other words, it will break when you assign values to the array which would do out-of-bounds.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Gordon, just try replacing
    Code:
    	for(int i = 0; i <= m_iRowCount; i++)
    	{
    		for(int j = 0; j <= m_iColCount; j++)
    		{
    with
    Code:
    	for(int i = 0; i < m_iRowCount; i++)
    	{
    		for(int j = 0; j < m_iColCount; j++)
    		{
    and see if the buffer still overflows

  11. #11
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Well turns out I initialized my m_iRowCount and m_iColCount later then I first needed them so there I go. Sorry for bothering with that stupid problem.

    Anyway thanks a lot everyone for help

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Uninitialized variables... Visual Studio detects them and triggers a runtime error if you use them without initializing them first.
    I'm surprised that you missed that, in case you are using VS.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    Quote Originally Posted by Elysia View Post
    Uninitialized variables... Visual Studio detects them and triggers a runtime error if you use them without initializing them first.
    I'm surprised that you missed that, in case you are using VS.
    I am surprised myself that VS let me do that... At least I can see that the starting function is not that useful in this case.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It will also spit out a warning for each unitialized variable that you use.
    Further, if you set warnings to max, it will also warn about potentially unused variables. Try to fix those, too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-11-2006, 06:46 PM
  2. I got an unhandled exception!!
    By LegendBreath in forum Game Programming
    Replies: 7
    Last Post: 04-19-2005, 01:55 PM
  3. unhandled exception error
    By trends in forum C++ Programming
    Replies: 4
    Last Post: 11-15-2002, 06:54 PM
  4. Unhandled exception
    By pdstatha in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2002, 06:03 PM
  5. Unhandled Exception
    By StringQuartet13 in forum C++ Programming
    Replies: 1
    Last Post: 03-04-2002, 05:18 PM