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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. "Encountered problem" message when closing

"Encountered problem" message when closing

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debuggingtutorialquestion
11 Posts 3 Posters 0 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.
  • A acerunner316

    I have a dialog based program using MFC. The program runs as expected when its opened. But when I close the dialog box (clicking the "X" or "esc"), I get the windows message "Program encountered an error and needs to be closed. We are sorry for the inconvenience." and askes to send error report. This happens almost every time I try to close. Since this is occuring only when closing, I have no idea how to debug this. Can anyone help? What could possibly be causing this?

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    What is the program doing when it closes? Are you able to comment out all nonessential code and still reproduce the problem? Does this happen in debug or relase mode, or both?


    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

    "Judge not by the eye but by the heart." - Native American Proverb

    A 1 Reply Last reply
    0
    • D David Crow

      What is the program doing when it closes? Are you able to comment out all nonessential code and still reproduce the problem? Does this happen in debug or relase mode, or both?


      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

      "Judge not by the eye but by the heart." - Native American Proverb

      A Offline
      A Offline
      acerunner316
      wrote on last edited by
      #3

      Just looking at the OnCancel() function, all I do is call a function that closes a driver (my program uses SDK provided to access drivers). I also deallocate a pointer to an array if its allocated. if (ptrArray) { delete []ptrArray; ptrArray = 0; } I thought this might be causing a problem, but I've had the "encountered problem" message before I put this code in. It occurs in both debug and release mode.

      D P 2 Replies Last reply
      0
      • A acerunner316

        Just looking at the OnCancel() function, all I do is call a function that closes a driver (my program uses SDK provided to access drivers). I also deallocate a pointer to an array if its allocated. if (ptrArray) { delete []ptrArray; ptrArray = 0; } I thought this might be causing a problem, but I've had the "encountered problem" message before I put this code in. It occurs in both debug and release mode.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #4

        acerunner316 wrote:

        It occurs in both debug...

        So what happens if you start the program using F5 (instead of Ctrl+F5)? Do you get any useful text in the debug window?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        A 1 Reply Last reply
        0
        • D David Crow

          acerunner316 wrote:

          It occurs in both debug...

          So what happens if you start the program using F5 (instead of Ctrl+F5)? Do you get any useful text in the debug window?


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          A Offline
          A Offline
          acerunner316
          wrote on last edited by
          #5

          I get this sometimes HEAP[.exe]: Invalid Address specified to RtlFreeHeap( 00390000, 0010F57C ) or sometimes i get The program .exe exited with code 0x2 I guess I should also note that I don't really know how to use the debugger. I'm a Visual C++ noob. I only use debug and release to check that my code works the same on both, and works as expected.

          D 1 Reply Last reply
          0
          • A acerunner316

            I get this sometimes HEAP[.exe]: Invalid Address specified to RtlFreeHeap( 00390000, 0010F57C ) or sometimes i get The program .exe exited with code 0x2 I guess I should also note that I don't really know how to use the debugger. I'm a Visual C++ noob. I only use debug and release to check that my code works the same on both, and works as expected.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #6

            acerunner316 wrote:

            HEAP[.exe]: Invalid Address specified to RtlFreeHeap( 00390000, 0010F57C )

            At any point in time are you changing the value of ptrArray?


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            A 1 Reply Last reply
            0
            • D David Crow

              acerunner316 wrote:

              HEAP[.exe]: Invalid Address specified to RtlFreeHeap( 00390000, 0010F57C )

              At any point in time are you changing the value of ptrArray?


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              A Offline
              A Offline
              acerunner316
              wrote on last edited by
              #7

              oh i just realized, i do intend to change the value, but it doesn't. The ptr is 0 or NULL when i'm not using it, but when i do, i use the new operator. I should really be using malloc so that it returns a pointer value, instead of taking the chance of trying to allocate (new) to ptr 0. Could that be the problem? But then why would it crash only when I close.

              D 1 Reply Last reply
              0
              • A acerunner316

                Just looking at the OnCancel() function, all I do is call a function that closes a driver (my program uses SDK provided to access drivers). I also deallocate a pointer to an array if its allocated. if (ptrArray) { delete []ptrArray; ptrArray = 0; } I thought this might be causing a problem, but I've had the "encountered problem" message before I put this code in. It occurs in both debug and release mode.

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #8

                How you have allocated memory for ptrArray. Can your show. One possible cause I see is deleting this memory twice(unintentionally may be).

                Prasad Notifier using ATL | Operator new[],delete[][^]

                A 1 Reply Last reply
                0
                • A acerunner316

                  oh i just realized, i do intend to change the value, but it doesn't. The ptr is 0 or NULL when i'm not using it, but when i do, i use the new operator. I should really be using malloc so that it returns a pointer value, instead of taking the chance of trying to allocate (new) to ptr 0. Could that be the problem? But then why would it crash only when I close.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  acerunner316 wrote:

                  I should really be using malloc...

                  No, you shouldn't be.

                  acerunner316 wrote:

                  But then why would it crash only when I close.

                  Check the value of the pointer variable after new is called and before delete is called.


                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                  "Judge not by the eye but by the heart." - Native American Proverb

                  1 Reply Last reply
                  0
                  • P prasad_som

                    How you have allocated memory for ptrArray. Can your show. One possible cause I see is deleting this memory twice(unintentionally may be).

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    A Offline
                    A Offline
                    acerunner316
                    wrote on last edited by
                    #10

                    Just to determin whether that was indeed problem, I got rid of the dynamic allocation of memory to that array. Instead, I set it to a fixed array size when its declared. But I still get that windows error message.

                    1 Reply Last reply
                    0
                    • A acerunner316

                      I have a dialog based program using MFC. The program runs as expected when its opened. But when I close the dialog box (clicking the "X" or "esc"), I get the windows message "Program encountered an error and needs to be closed. We are sorry for the inconvenience." and askes to send error report. This happens almost every time I try to close. Since this is occuring only when closing, I have no idea how to debug this. Can anyone help? What could possibly be causing this?

                      A Offline
                      A Offline
                      acerunner316
                      wrote on last edited by
                      #11

                      Can someone explain PostNcDestroy()? I saw it in some sample code, and I tried to look it up but couldn't quite understand the need for it.

                      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