From: Tomas Frydrych (tomas@frydrych.uklinux.net)
Date: Thu Aug 01 2002 - 14:49:18 EDT
I have fixed a small problem in the changes I have made yesterday 
that allow us to avoid at least some unnecessary font loading on 
win32. I have also added a lengthy comment inside 
gr_UnixGraphics::setFont(), for I am almost certain the method used 
there to shortciruit font loading is not safe, but I did not change the 
code, as I do not like to make untested commits.
The problem applies to all of our graphics classes, so I migh just as 
well give the gist of it here.
Some of the graphics classes (I noticed unix and qnx) chache a 
pointer to the font set with gr_*Graphics::setFont() and then on next 
call compare the new font with the one pointed to by the cached 
pointer. The problem is that the font allocation / deallocation does 
not happen inside the graphics class, so there is no way of knowing 
if the cached pointer is still valid. Consider case like this
        f1  = new Gr_Font();
        ::setFont(f1);
        delete f1;
      f2 = new Gr_Font(); // a completely different font
        ::setFont(f2);
obviously the font pointer cached in the graphics after the first 
setFont() is no longer valid, it can point to garbage on the heap, or, 
very likely, if the delete/new are immediately successive, to f2.
I have got around this by assigning each font a unique id at 
allocation time and caching the id, not the font, in the graphics 
class. If the id remains the same between calls to setFont(), then we 
know the fonts too are the same. This is not 100% efficient, but it 
catches out lot of the duplicates and is very fast. I would like to 
suggest that the same method is used in all of the graphics classes.
These changes should be backported
Tomas
This archive was generated by hypermail 2.1.4 : Thu Aug 01 2002 - 14:58:36 EDT