Double Buffering vs. Private DC's
-
To accomplish smooth, fast graphics that don't flicker which is better, double buffering or private DC's? Mark Lenz
I'm having a problem where it looks like I'm running out of device contexts. I have a control which looks kinda like a fuel guage. The value that the needle represents is updated about every second, so the needle must be redrawn about every second. I have about 4 or 5 of these controls in my view. When I have been displaying the view for about 3 minutes, things start to get weird. All of my fonts revert to a standard font and it starts to draw white where there was supposed to another color. This starts to affect the title bar, making it white. Sometimes it even starts to affect other applications. Does anyone know what's happening and maybe what I could do to stop this? I have looked everywhere, Google, MSDN, MSJ and mailing list archives, but I don't really know what's going on so I don't really know what to look for. Thanks. Mark Lenz
-
I'm having a problem where it looks like I'm running out of device contexts. I have a control which looks kinda like a fuel guage. The value that the needle represents is updated about every second, so the needle must be redrawn about every second. I have about 4 or 5 of these controls in my view. When I have been displaying the view for about 3 minutes, things start to get weird. All of my fonts revert to a standard font and it starts to draw white where there was supposed to another color. This starts to affect the title bar, making it white. Sometimes it even starts to affect other applications. Does anyone know what's happening and maybe what I could do to stop this? I have looked everywhere, Google, MSDN, MSJ and mailing list archives, but I don't really know what's going on so I don't really know what to look for. Thanks. Mark Lenz
I bet you're on 9x, right? That usually means you've exhausted your process's GDI resources or filled the GDI heap (which is limited to 64K on 9x, due to 16-bit limitations). Are you making new GDI objects (pens, brushes, etc.) every time you paint your control? And if so, are you deleting those objects? --Mike-- "COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell." -- John Simmons, 1/22/2002 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
-
I bet you're on 9x, right? That usually means you've exhausted your process's GDI resources or filled the GDI heap (which is limited to 64K on 9x, due to 16-bit limitations). Are you making new GDI objects (pens, brushes, etc.) every time you paint your control? And if so, are you deleting those objects? --Mike-- "COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell." -- John Simmons, 1/22/2002 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
You're right, I am on Windows 98. I have been using SaveDC() and RestoreDC(). I also declare all of my GDI objects that I will need in my OnPaint method at the beginning, so that they are all on the same scope. So, everytime the OnPaint() method is called I SaveDC() and create new GDI objects, use them, and when I'm done call RestoreDC() and the objects should be deleted when they go out of scope. Am I doing this wrong? Thanks. Mark Lenz
-
I bet you're on 9x, right? That usually means you've exhausted your process's GDI resources or filled the GDI heap (which is limited to 64K on 9x, due to 16-bit limitations). Are you making new GDI objects (pens, brushes, etc.) every time you paint your control? And if so, are you deleting those objects? --Mike-- "COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell." -- John Simmons, 1/22/2002 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.
-
You're right, I am on Windows 98. I have been using SaveDC() and RestoreDC(). I also declare all of my GDI objects that I will need in my OnPaint method at the beginning, so that they are all on the same scope. So, everytime the OnPaint() method is called I SaveDC() and create new GDI objects, use them, and when I'm done call RestoreDC() and the objects should be deleted when they go out of scope. Am I doing this wrong? Thanks. Mark Lenz
As Mr. Dunn mentioned above, Windows 98 is very sensitive to resource leaks. However, you can usually detect when this is happening on Windows 2000 by using the task manager. Display the processes page, use the View->Select Columns menu to display the GDI Objects column, and watch the number for your application. If there is a constant increase while it is running, then you've detected the resource leak (this is safer than running the app in Win95/Win98, since resource leaks can cause those OSs to become unstable). Once you can quickly identify the resource leak, modify your code by commenting out lines that create and use GDI resources, one at a time. In this way you should be able to identify which resources are not being released. The method you're describing sounds like it should be working; however, because you're relying on automatic deletion of the objects there is no easy way to verify that it is successful. Inserting temporary
DeleteObject()
calls before the objects go out of scope might also be a good way to narrow down the search:VERIFY(gdiObj.DeleteObject());
If this line ASSERT()s, then you've found a problem. And if you can reduce your problem to a few lines of code (i.e.CPen pen(PS_SOLID, 1, RGB(0,255,0)); int nSave = dc.SaveDC(); dc.SelectObject(&pen); VERIFY(dc.RestoreDC(nSave)); VERIFY(pen.DeleteObject());
) then post it here, & someone will prolly figure it out. farewell goodnight last one out turn out the lightsSmashing Pumpkins, Tales of a Scorched Earth
-
You're right, I am on Windows 98. I have been using SaveDC() and RestoreDC(). I also declare all of my GDI objects that I will need in my OnPaint method at the beginning, so that they are all on the same scope. So, everytime the OnPaint() method is called I SaveDC() and create new GDI objects, use them, and when I'm done call RestoreDC() and the objects should be deleted when they go out of scope. Am I doing this wrong? Thanks. Mark Lenz
So, you're still making a lot of GDI objects, since you repaint the controls often. First thing I'd suggest is to move the GDI objects so they're memeber variables of the control classes, so that you only create the objects once. And btw, the problem doesn't appear on 2000 because NT doesn't have the 16-bit limitations that 9x does. --Mike-- "COM didn't solve the old version of DLL hell - it just provided us with a new and improved version of hell." -- John Simmons, 1/22/2002 My really out-of-date homepage Sonork - 100.10414 AcidHelm Big fan of Alyson Hannigan.