Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. !UPDATED! Debug works but release crashes (this one's tricky)

!UPDATED! Debug works but release crashes (this one's tricky)

Scheduled Pinned Locked Moved C / C++ / MFC
helpannouncementdatabasedebuggingtutorial
10 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boxmonkey
    wrote on last edited by
    #1

    Original message: I have read the codeproject article about Finding crash information using the MAP file, which was helpful, but I'm stuck. I have a very complex program full of dialog boxes that are derived from a class that is derived from CDialog. Inside these dialogs are a bunch of edit boxes of type CTableFieldEdit, which is derived from CEdit. The program works beautifully in debug mode, but crashes in release mode some time between when I create the dialog item and when I call DoModal() From what I've been able to determine, the crash happens in MFC42.dll, but it crashes in two different places, depending on which dialog I'm calling. Some of the dialogs crash at the address for GetStyle and some of them crash after the address for ScrollWindowEx, according to the map file. I have already turned off all optimizations. I'm stuck. What might I be doing wrong? I can post some or all of the code if it will help. I can even post the entire project if you like, but you won't be able to run the program as it connects to a database. Thanks! Update: The problem seems to be related to how I handle message maps in my derived dialog classes, but I don't know how to fix it or why it works correctly in Debug mode, but not Release mode. Here's what's happening: My Dialog boxes are derived from CFormHelperDlg, which is a class I made to reduce code redundancy. CFormHelperDlg is derived from CDialog. There are certain messages I want to handle in CFormHelperDlg rather than in the class for each given dialog (since all the code is redundant), so I set up my message maps as such: In CJailDialog (which is derived from CFormHelperDlg): BEGIN_MESSAGE_MAP(CJailDialog, CFormHelperDlg) //{{AFX_MSG_MAP(CJailDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() In CFormHelperDlg (which is derived from CDialog): BEGIN_MESSAGE_MAP(CFormHelperDlg, CDialog) //{{AFX_MSG_MAP(CFormHelperDlg) ON_BN_CLICKED(IDC_BUTTON_JAN, OnButtonJan) ON_BN_CLICKED(IDC_BUTTON_FEB, OnButtonFeb) ON_BN_CLICKED(IDC_BUTTON_MAR, OnButtonMar) ON_BN_CLICKED(IDC_BUTTON_APR, OnButtonApr) ON_BN_CLICKED(IDC_BUTTON_MAY, OnButtonMay) ON_BN_CLICKED(IDC_BUTTON_JUN, OnButtonJun) ON_BN_CLICKED(IDC_BUTTON_JUL, OnButtonJul) ON_BN_CLICKED(IDC_BUTTON_AUG, OnButtonAug) ON_BN_CLICKED(IDC_BUTTON_SEP, OnButtonSep) ON_BN_CLICKED(IDC_BUTTON_OCT, OnButtonOct) ON_BN_CLICKED(IDC_BUTTON_NOV, OnButtonNov) ON_BN_CLICKED(IDC_BUTTON_DEC, OnButtonDec) ON_BN_CLICKED(IDC_MANAGER_SIGNOFF, OnManagerSignoff) ON_ME

    R PJ ArendsP Y 3 Replies Last reply
    0
    • B boxmonkey

      Original message: I have read the codeproject article about Finding crash information using the MAP file, which was helpful, but I'm stuck. I have a very complex program full of dialog boxes that are derived from a class that is derived from CDialog. Inside these dialogs are a bunch of edit boxes of type CTableFieldEdit, which is derived from CEdit. The program works beautifully in debug mode, but crashes in release mode some time between when I create the dialog item and when I call DoModal() From what I've been able to determine, the crash happens in MFC42.dll, but it crashes in two different places, depending on which dialog I'm calling. Some of the dialogs crash at the address for GetStyle and some of them crash after the address for ScrollWindowEx, according to the map file. I have already turned off all optimizations. I'm stuck. What might I be doing wrong? I can post some or all of the code if it will help. I can even post the entire project if you like, but you won't be able to run the program as it connects to a database. Thanks! Update: The problem seems to be related to how I handle message maps in my derived dialog classes, but I don't know how to fix it or why it works correctly in Debug mode, but not Release mode. Here's what's happening: My Dialog boxes are derived from CFormHelperDlg, which is a class I made to reduce code redundancy. CFormHelperDlg is derived from CDialog. There are certain messages I want to handle in CFormHelperDlg rather than in the class for each given dialog (since all the code is redundant), so I set up my message maps as such: In CJailDialog (which is derived from CFormHelperDlg): BEGIN_MESSAGE_MAP(CJailDialog, CFormHelperDlg) //{{AFX_MSG_MAP(CJailDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() In CFormHelperDlg (which is derived from CDialog): BEGIN_MESSAGE_MAP(CFormHelperDlg, CDialog) //{{AFX_MSG_MAP(CFormHelperDlg) ON_BN_CLICKED(IDC_BUTTON_JAN, OnButtonJan) ON_BN_CLICKED(IDC_BUTTON_FEB, OnButtonFeb) ON_BN_CLICKED(IDC_BUTTON_MAR, OnButtonMar) ON_BN_CLICKED(IDC_BUTTON_APR, OnButtonApr) ON_BN_CLICKED(IDC_BUTTON_MAY, OnButtonMay) ON_BN_CLICKED(IDC_BUTTON_JUN, OnButtonJun) ON_BN_CLICKED(IDC_BUTTON_JUL, OnButtonJul) ON_BN_CLICKED(IDC_BUTTON_AUG, OnButtonAug) ON_BN_CLICKED(IDC_BUTTON_SEP, OnButtonSep) ON_BN_CLICKED(IDC_BUTTON_OCT, OnButtonOct) ON_BN_CLICKED(IDC_BUTTON_NOV, OnButtonNov) ON_BN_CLICKED(IDC_BUTTON_DEC, OnButtonDec) ON_BN_CLICKED(IDC_MANAGER_SIGNOFF, OnManagerSignoff) ON_ME

      R Offline
      R Offline
      Roger Allen
      wrote on last edited by
      #2

      Can you not add debug info to your appplication in release mode? This will allow you do run the software and get a call stack of where the crash occurs. From there you can backtrack to your most recent code that ran and hopefully find the problem. If you vote me down, my score will only get lower

      B 1 Reply Last reply
      0
      • B boxmonkey

        Original message: I have read the codeproject article about Finding crash information using the MAP file, which was helpful, but I'm stuck. I have a very complex program full of dialog boxes that are derived from a class that is derived from CDialog. Inside these dialogs are a bunch of edit boxes of type CTableFieldEdit, which is derived from CEdit. The program works beautifully in debug mode, but crashes in release mode some time between when I create the dialog item and when I call DoModal() From what I've been able to determine, the crash happens in MFC42.dll, but it crashes in two different places, depending on which dialog I'm calling. Some of the dialogs crash at the address for GetStyle and some of them crash after the address for ScrollWindowEx, according to the map file. I have already turned off all optimizations. I'm stuck. What might I be doing wrong? I can post some or all of the code if it will help. I can even post the entire project if you like, but you won't be able to run the program as it connects to a database. Thanks! Update: The problem seems to be related to how I handle message maps in my derived dialog classes, but I don't know how to fix it or why it works correctly in Debug mode, but not Release mode. Here's what's happening: My Dialog boxes are derived from CFormHelperDlg, which is a class I made to reduce code redundancy. CFormHelperDlg is derived from CDialog. There are certain messages I want to handle in CFormHelperDlg rather than in the class for each given dialog (since all the code is redundant), so I set up my message maps as such: In CJailDialog (which is derived from CFormHelperDlg): BEGIN_MESSAGE_MAP(CJailDialog, CFormHelperDlg) //{{AFX_MSG_MAP(CJailDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() In CFormHelperDlg (which is derived from CDialog): BEGIN_MESSAGE_MAP(CFormHelperDlg, CDialog) //{{AFX_MSG_MAP(CFormHelperDlg) ON_BN_CLICKED(IDC_BUTTON_JAN, OnButtonJan) ON_BN_CLICKED(IDC_BUTTON_FEB, OnButtonFeb) ON_BN_CLICKED(IDC_BUTTON_MAR, OnButtonMar) ON_BN_CLICKED(IDC_BUTTON_APR, OnButtonApr) ON_BN_CLICKED(IDC_BUTTON_MAY, OnButtonMay) ON_BN_CLICKED(IDC_BUTTON_JUN, OnButtonJun) ON_BN_CLICKED(IDC_BUTTON_JUL, OnButtonJul) ON_BN_CLICKED(IDC_BUTTON_AUG, OnButtonAug) ON_BN_CLICKED(IDC_BUTTON_SEP, OnButtonSep) ON_BN_CLICKED(IDC_BUTTON_OCT, OnButtonOct) ON_BN_CLICKED(IDC_BUTTON_NOV, OnButtonNov) ON_BN_CLICKED(IDC_BUTTON_DEC, OnButtonDec) ON_BN_CLICKED(IDC_MANAGER_SIGNOFF, OnManagerSignoff) ON_ME

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        http://www.codeproject.com/debug/survivereleasever.asp[^]


        [

        ](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        B 1 Reply Last reply
        0
        • R Roger Allen

          Can you not add debug info to your appplication in release mode? This will allow you do run the software and get a call stack of where the crash occurs. From there you can backtrack to your most recent code that ran and hopefully find the problem. If you vote me down, my score will only get lower

          B Offline
          B Offline
          boxmonkey
          wrote on last edited by
          #4

          Call stack looks like this: CWnd::GetStyle(const CWnd * const 0x0012f758 {CJailDialog hWnd=0x002d0b20}) line 195 + 1 byte _AfxHandleActivate(CWnd * 0x0012f758 {CJailDialog hWnd=0x002d0b20}, unsigned int 1, CWnd * 0x00323fc0 {CMainFrame hWnd=0x003f011c}) line 145 + 11 bytes MFC42! 5f401be9() CWnd::WindowProc(CWnd * const 0x0012f758 {CJailDialog hWnd=0x002d0b20}, unsigned int 6, unsigned int 1, long 4129052) line 1596 + 27 bytes AfxCallWndProc(CWnd * 0x0012f758 {CJailDialog hWnd=0x002d0b20}, HWND__ * 0x00000000, unsigned int 6, unsigned int 1, long 4129052) line 218 AfxWndProc(HWND__ * 0x002d0b20, unsigned int 6, unsigned int 1, long 4129052) line 377 + 16 bytes AfxWndProcBase(HWND__ * 0x002d0b20, unsigned int 6, unsigned int 1, long 4129052) line 220 + 21 bytes USER32! 77d43a50() USER32! 77d43b1f() USER32! 77d444f5() USER32! 77d44525() NTDLL! 77f75da3() 58000080() I don't know about you, but that doesn't seem very helpful to me...

          1 Reply Last reply
          0
          • PJ ArendsP PJ Arends

            http://www.codeproject.com/debug/survivereleasever.asp[^]


            [

            ](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!

            B Offline
            B Offline
            boxmonkey
            wrote on last edited by
            #5

            Alas, I had already read this article, to no avail.

            1 Reply Last reply
            0
            • B boxmonkey

              Original message: I have read the codeproject article about Finding crash information using the MAP file, which was helpful, but I'm stuck. I have a very complex program full of dialog boxes that are derived from a class that is derived from CDialog. Inside these dialogs are a bunch of edit boxes of type CTableFieldEdit, which is derived from CEdit. The program works beautifully in debug mode, but crashes in release mode some time between when I create the dialog item and when I call DoModal() From what I've been able to determine, the crash happens in MFC42.dll, but it crashes in two different places, depending on which dialog I'm calling. Some of the dialogs crash at the address for GetStyle and some of them crash after the address for ScrollWindowEx, according to the map file. I have already turned off all optimizations. I'm stuck. What might I be doing wrong? I can post some or all of the code if it will help. I can even post the entire project if you like, but you won't be able to run the program as it connects to a database. Thanks! Update: The problem seems to be related to how I handle message maps in my derived dialog classes, but I don't know how to fix it or why it works correctly in Debug mode, but not Release mode. Here's what's happening: My Dialog boxes are derived from CFormHelperDlg, which is a class I made to reduce code redundancy. CFormHelperDlg is derived from CDialog. There are certain messages I want to handle in CFormHelperDlg rather than in the class for each given dialog (since all the code is redundant), so I set up my message maps as such: In CJailDialog (which is derived from CFormHelperDlg): BEGIN_MESSAGE_MAP(CJailDialog, CFormHelperDlg) //{{AFX_MSG_MAP(CJailDialog) //}}AFX_MSG_MAP END_MESSAGE_MAP() In CFormHelperDlg (which is derived from CDialog): BEGIN_MESSAGE_MAP(CFormHelperDlg, CDialog) //{{AFX_MSG_MAP(CFormHelperDlg) ON_BN_CLICKED(IDC_BUTTON_JAN, OnButtonJan) ON_BN_CLICKED(IDC_BUTTON_FEB, OnButtonFeb) ON_BN_CLICKED(IDC_BUTTON_MAR, OnButtonMar) ON_BN_CLICKED(IDC_BUTTON_APR, OnButtonApr) ON_BN_CLICKED(IDC_BUTTON_MAY, OnButtonMay) ON_BN_CLICKED(IDC_BUTTON_JUN, OnButtonJun) ON_BN_CLICKED(IDC_BUTTON_JUL, OnButtonJul) ON_BN_CLICKED(IDC_BUTTON_AUG, OnButtonAug) ON_BN_CLICKED(IDC_BUTTON_SEP, OnButtonSep) ON_BN_CLICKED(IDC_BUTTON_OCT, OnButtonOct) ON_BN_CLICKED(IDC_BUTTON_NOV, OnButtonNov) ON_BN_CLICKED(IDC_BUTTON_DEC, OnButtonDec) ON_BN_CLICKED(IDC_MANAGER_SIGNOFF, OnManagerSignoff) ON_ME

              Y Offline
              Y Offline
              Yawar Maajed
              wrote on last edited by
              #6

              what is function signature of your OnInitDialog member, if it is anything other than LRESULT OnInitDialog(WPARAM wParam, LPARAM lParam) the application is bound to crash in release mode. Remember, OnInitDialog function is provided as a virtual function in CDialog already, and if you want to handle the WM_INITDIALOG message yourself, you need to at least name it differently, the way you are doing it, you are probably declaing it as virtual BOOL OnInitDialog(); /yawar I have no signature

              Y B D 3 Replies Last reply
              0
              • Y Yawar Maajed

                what is function signature of your OnInitDialog member, if it is anything other than LRESULT OnInitDialog(WPARAM wParam, LPARAM lParam) the application is bound to crash in release mode. Remember, OnInitDialog function is provided as a virtual function in CDialog already, and if you want to handle the WM_INITDIALOG message yourself, you need to at least name it differently, the way you are doing it, you are probably declaing it as virtual BOOL OnInitDialog(); /yawar I have no signature

                Y Offline
                Y Offline
                Yawar Maajed
                wrote on last edited by
                #7

                I think I need to provide a little explanation of my response too, look at the expansion of ON_MESSAGE macro in AFXMSG_.H file #define ON_MESSAGE(message, memberFxn) \ { message, 0, 0, 0, AfxSig_lwl, \ (AFX_PMSG)(AFX_PMSGW)(LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))&memberFxn }, Anything you put in ON_MESSAGE macro has to have this declaration, the compiler generates the code and assumes that your function will have a return type of LRESULT and will take two parameters, WPARAM and LPARAM. If you declare return type different or make parameters different, you will end up corrupting the stack and hence the crash in release mode. answer to question that why this won't crash in debug mode is simple, the debug executable has a lot of guard bytes before and after function calls, those bytes get corrupted but stack does not. Probably if the target function signature would be too big (20+ parameters) it will crash in debug too. Let me know if this was the reason. I have gone in too much detail without even knowing if your bug really was because of bad function signature. Ciao, /yawar

                1 Reply Last reply
                0
                • Y Yawar Maajed

                  what is function signature of your OnInitDialog member, if it is anything other than LRESULT OnInitDialog(WPARAM wParam, LPARAM lParam) the application is bound to crash in release mode. Remember, OnInitDialog function is provided as a virtual function in CDialog already, and if you want to handle the WM_INITDIALOG message yourself, you need to at least name it differently, the way you are doing it, you are probably declaing it as virtual BOOL OnInitDialog(); /yawar I have no signature

                  B Offline
                  B Offline
                  boxmonkey
                  wrote on last edited by
                  #8

                  You, sir, are a life saver. I assumed that: a) Since Visual Studio generated the message handler for me, it must be right (ha!) and b) Since CFormHelperDlg calls CDialog::OnInitDialog(), it would be ok My understanding of how all this stuff works starts to get pretty cloudy when it comes to areas like this. Thanks again for the help.

                  Y 1 Reply Last reply
                  0
                  • B boxmonkey

                    You, sir, are a life saver. I assumed that: a) Since Visual Studio generated the message handler for me, it must be right (ha!) and b) Since CFormHelperDlg calls CDialog::OnInitDialog(), it would be ok My understanding of how all this stuff works starts to get pretty cloudy when it comes to areas like this. Thanks again for the help.

                    Y Offline
                    Y Offline
                    Yawar Maajed
                    wrote on last edited by
                    #9

                    :) glad to have helped.. have fun /yawar

                    1 Reply Last reply
                    0
                    • Y Yawar Maajed

                      what is function signature of your OnInitDialog member, if it is anything other than LRESULT OnInitDialog(WPARAM wParam, LPARAM lParam) the application is bound to crash in release mode. Remember, OnInitDialog function is provided as a virtual function in CDialog already, and if you want to handle the WM_INITDIALOG message yourself, you need to at least name it differently, the way you are doing it, you are probably declaing it as virtual BOOL OnInitDialog(); /yawar I have no signature

                      D Offline
                      D Offline
                      dahill
                      wrote on last edited by
                      #10

                      This problem looks similar to mine. Unfortunately, I don't understand this answer. When I change the 'signature' of my own OnInitDialog function to match your suggestion, it doesn't get called, even in DEBUG. Any more enlightenment to offer?:confused: dahill

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups