[WIN] Re: Win32Lib: problem with setFont in RichEdit

new topic     » topic index » view thread      » older message » newer message

Matt Lewis wrote:

> If Dave could explain to me (privately or publicly)
> what he found going wrong before, I'd be happy to take
> a look at it.

There may indeed be a font leak in Win32Lib, but I don't know where. The
best plan is to write a 'stress test' that is perform a particular action in
a loop infinitely. If the resources are eventually exhausted, there's a bug.

There were some bugs in the code that allowed DCs of zero to be passed to
routines. When you changed the font of the zero DC, you altered the system
font.

I added the lower end range check to valid id ( id<0), and pasted the test
throughout the code. I closed a couple of leaks that the test identified.

The emulated tooltips seemed to be causing a similar problem. I added a
stress test to the emulted tooltips (triggering and clearing them), and was
able to find some bugs that way (which led to the fix I outlined above).
Since then,  there were some reported issues which I wasn't able to
duplicate it on my machine.

Some things to keep in mind:

1.  Windows resources of different types (say, fonts vs. bitmaps) can share
the same ID number. This was causing errors in the resource tracking code
(in the form of resource leaks). That's why the control id is part of the
resource tracking. This can be a bit confusing.

2. Writing to the screen can cause the system font to temporarily change,
which is why it's important to set it back when you're done.

3. The core of the font code is based on Charles Petzold's routines, and
some of the DC stuff is still a bit mysterious to me.

4. There are programs like Resource Meter (Programs | Accessories | System
Tools | Resource Meter ) that can be used to monitor the state of GDI
resources. This may be useful as well, especially when you are running a
stress test. Keep in mind that Win32Lib doesn't release *all* the resources
until it's closed.

Resource leakage is a major issue for any Windows application, and they can
be hard to track down. My brother works in tech support for a large company;
their main helpdesk app leaks resources. Rather than fix it, they just made
it standard procedure to reboot the machines every morning. I'd prefer that
Win32Lib had a real fix.

I hope this helps!

-- David Cuny

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu