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. GUI goes all funny and system hangs

GUI goes all funny and system hangs

Scheduled Pinned Locked Moved C / C++ / MFC
c++toolshelpquestionlounge
6 Posts 4 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.
  • L Offline
    L Offline
    louis 0
    wrote on last edited by
    #1

    Guys, What would cause my PC's graphic display to behave all funny and the system eventually to crash? Are there any tools that would be able to give me some kind of direction in locating the problem. What can I do using MS VC++ tools. The program that I run is quite big with 65 threads, a plethora of supporting files, MDI interface, and dialog boxes. I am running NT with Service Pack 6.0, VC++ 6.0 Any general advice will be appreciated. Thanks Louis :confused:

    K R P 3 Replies Last reply
    0
    • L louis 0

      Guys, What would cause my PC's graphic display to behave all funny and the system eventually to crash? Are there any tools that would be able to give me some kind of direction in locating the problem. What can I do using MS VC++ tools. The program that I run is quite big with 65 threads, a plethora of supporting files, MDI interface, and dialog boxes. I am running NT with Service Pack 6.0, VC++ 6.0 Any general advice will be appreciated. Thanks Louis :confused:

      K Offline
      K Offline
      KaRl
      wrote on last edited by
      #2

      louis wrote: What would cause my PC's graphic display to behave all funny The problem may come from the use of graphical objects (as pens or fonts), selected in a device context which is released without reassigning before the original GUI objects. For example, the following (dummy) code is wrong: { CDC myDC; CPen myPen; myPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); myDC.SelectObject(myPen); myDC.LineTo(0, 0); } This one is good { CDC myDC; CPen myPen; CPen *pOldPen; myPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); pOldPen = myDC.SelectObject(myPen); myDC.LineTo(0, 0); myDC.SelectObject(pOldPen); // select initial GUI objects } HTH,


      Ohé Partisans, Ouvriers et Paysans C'est l'alarme! Le Chant des Partisans

      L 1 Reply Last reply
      0
      • L louis 0

        Guys, What would cause my PC's graphic display to behave all funny and the system eventually to crash? Are there any tools that would be able to give me some kind of direction in locating the problem. What can I do using MS VC++ tools. The program that I run is quite big with 65 threads, a plethora of supporting files, MDI interface, and dialog boxes. I am running NT with Service Pack 6.0, VC++ 6.0 Any general advice will be appreciated. Thanks Louis :confused:

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

        We had this very same kind of problem in one of our apps. We knew it was caused by a resource leak, but I had spent weeks trying to fix it. All GDI objects I allocated were check/destroyed etc, but it still persisted until quite recently when we found the culprit:

        SHGetFileInfo(path, 0, &fileinfo, sizeof(fileinfo), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_SHELLICONSIZE);

        It seems that this system procedure allocates an icon that you need to destroy yourself. If your using this call make sure you call the corresponding DestoryIcon() on the member var listed in the MSDN fo a SHFILEINFO object. Roger Allen Sonork 100.10016 In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!

        L 1 Reply Last reply
        0
        • L louis 0

          Guys, What would cause my PC's graphic display to behave all funny and the system eventually to crash? Are there any tools that would be able to give me some kind of direction in locating the problem. What can I do using MS VC++ tools. The program that I run is quite big with 65 threads, a plethora of supporting files, MDI interface, and dialog boxes. I am running NT with Service Pack 6.0, VC++ 6.0 Any general advice will be appreciated. Thanks Louis :confused:

          P Offline
          P Offline
          perlmunger
          wrote on last edited by
          #4

          I've had this same problem myself. You have a resource leak (as others have noted). If you want to debug your resource consumption, you can use the task manager. Now, I'm not sure that this is the same in NT, but under Win2K open the Task Manager and select the "Process" tab. Then click the "View | Set Columns..." menu item. In the resulting dialog, make sure you have "GDI Objects" checked and click "Ok". Now, run your application and watch the "GDI Objects" column. You will, in all liklihood, see your object count go up to something like 8000 or 9000 and then crash. At least that's what happened to me. As others have noted you need to release your resources when you're done using them including any new DCs you've created. Make sure you call ReleaseDC on any new DCs you've created with CreateCompatibleDC, or any other DC creation mechanism, when you're done with it. This is where the vast majority of my problems were. Once I fixed them all, my app only used 34 GDI objects (on average). Hope this helps. -Matt ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

          1 Reply Last reply
          0
          • K KaRl

            louis wrote: What would cause my PC's graphic display to behave all funny The problem may come from the use of graphical objects (as pens or fonts), selected in a device context which is released without reassigning before the original GUI objects. For example, the following (dummy) code is wrong: { CDC myDC; CPen myPen; myPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); myDC.SelectObject(myPen); myDC.LineTo(0, 0); } This one is good { CDC myDC; CPen myPen; CPen *pOldPen; myPen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0)); pOldPen = myDC.SelectObject(myPen); myDC.LineTo(0, 0); myDC.SelectObject(pOldPen); // select initial GUI objects } HTH,


            Ohé Partisans, Ouvriers et Paysans C'est l'alarme! Le Chant des Partisans

            L Offline
            L Offline
            louis 0
            wrote on last edited by
            #5

            Thank you very much. Your advice is highly appreciated. I have gone thru the graphical objects as suggested. All code seem to be implemented the correct way. I intent to go thru it again to confirm. An interesting comment by someone else is to monitor the GDI Objects in Task Manager. I however are unable to activate it in NT. Any advice here. Thanks. Louis

            1 Reply Last reply
            0
            • R Roger Allen

              We had this very same kind of problem in one of our apps. We knew it was caused by a resource leak, but I had spent weeks trying to fix it. All GDI objects I allocated were check/destroyed etc, but it still persisted until quite recently when we found the culprit:

              SHGetFileInfo(path, 0, &fileinfo, sizeof(fileinfo), SHGFI_ICON | SHGFI_SMALLICON | SHGFI_SHELLICONSIZE);

              It seems that this system procedure allocates an icon that you need to destroy yourself. If your using this call make sure you call the corresponding DestoryIcon() on the member var listed in the MSDN fo a SHFILEINFO object. Roger Allen Sonork 100.10016 In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!

              L Offline
              L Offline
              louis 0
              wrote on last edited by
              #6

              Thank you very much. I do appreciate your advice. I have gone thru your suggestions. All code are implemented the correct way, i.e all are destroyed afterwards except for one occurence. This i have corrected but the problem still remains. An interesting comment by someone else is to monitor the GDI Objects in Task Manager. I however are unable to activate it in NT. Any advice here. Thanks. Louis

              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