4.01 - Graphics Problem with Windows 98 but not NT or 2000 
Author Message
 4.01 - Graphics Problem with Windows 98 but not NT or 2000

Friends,

My Dolphin app has a rather elaborate custom widget that paints lines and
text on a canvas. It is resizeable, so it determines the position of things
based on the size of the canvas.

When I run it on Windows98 the coordinates all seem to be measured from the
x/y origin of the monitor, rather than of the canvas. As a result, the app
is painting lines and text all over the screen, mostly near the upper
left-hand corner of the monitor - but not on the canvas itself. Even when I
move the shell around, the characters and lines are positioned relative to
the monitor.

Runs perfectly on NT and Win2000.

Any thoughts ? Am I using a bunch of deprecated methods ?

Best wishes, and thanks,

Ken



Wed, 10 Sep 2003 06:14:23 GMT  
 4.01 - Graphics Problem with Windows 98 but not NT or 2000
Ken,

Quote:
> My Dolphin app has a rather elaborate custom widget that paints lines and
> text on a canvas. It is resizeable, so it determines the position of
things
> based on the size of the canvas.

> When I run it on Windows98 the coordinates all seem to be measured from
the
> x/y origin of the monitor, rather than of the canvas. As a result, the app
> is painting lines and text all over the screen, mostly near the upper
> left-hand corner of the monitor - but not on the canvas itself. Even when
I
> move the shell around, the characters and lines are positioned relative to
> the monitor.

You'll find that it will do the same thing on Win95 too.  I tracked this
down to Font>>initialize, which has been changed for the benefit of console
app stripping.  The following change:

Font>>initialize
 "Initialise the receiver."

 super initialize.
 (logfont := LOGFONT new) lfWeight: FW_NORMAL.

 "This is it:  revert to 4.0:
 resolution := Canvas forDesktop resolution."
 resolution := View desktop resolution.

fixed my app which was doing exactly what you describe.  Even though the
more stable OSs do ok with the 4.01 code, I think (if I'm following it) that
it should be changed, as it creates and finalizes an HDC every time a font
is created.

The part I don't understand is why Win9x machines draw all over the desktop,
why they don't seem to crash as a result, and why the behavior is so
consitent.  Did you also find that it tended to do the same thing every
time?

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.



Wed, 10 Sep 2003 08:50:42 GMT  
 4.01 - Graphics Problem with Windows 98 but not NT or 2000
Bill -

Quote:
> You'll find that it will do the same thing on Win95 too.  I tracked
this
> down to Font>>initialize, which has been changed for the benefit of
console
> app stripping.  The following change:

> Font>>initialize
>  "Initialise the receiver."

>  super initialize.
>  (logfont := LOGFONT new) lfWeight: FW_NORMAL.

>  "This is it:  revert to 4.0:
>  resolution := Canvas forDesktop resolution."
>  resolution := View desktop resolution.

> fixed my app which was doing exactly what you describe.  Even though
the
> more stable OSs do ok with the 4.01 code, I think (if I'm following
it) that
> it should be changed, as it creates and finalizes an HDC every time a
font
> is created.

> The part I don't understand is why Win9x machines draw all over the
desktop,
> why they don't seem to crash as a result, and why the behavior is so
> consitent.  Did you also find that it tended to do the same thing
every
> time?

Yes, it was pretty consistent. However, I noticed that it painted all
over the desktop, and then also on the canvas, correctly, at times...oh
well.

In any event, your fix worked ! Thanks so much !

Best wishes,

Ken



Wed, 10 Sep 2003 20:49:56 GMT  
 4.01 - Graphics Problem with Windows 98 but not NT or 2000

Quote:
> Bill -

> > You'll find that it will do the same thing on Win95 too.  I tracked
> this
> > down to Font>>initialize, which has been changed for the benefit of
> console
> > app stripping....

Hats off to Bill for find the cause of the problem.

It is in fact a resource exhaustion problem, though not a resource leak. The
new Font initialize method is allocating a desktop Device Context, but
leaving it to be released by finalisation. Consequently the DCs are returned
to the OS as a "background" activity triggered by garbage collection.
Although this usually happens fairly quickly, it is not immediate. This is
fine on NT/2k, because there is no arbitrary limit on DCs, but on Windows
95/98 (to quote from MSDN): "Windows 95/98: There are only 5 common DCs
available per
thread, thus failure to release a DC can prevent other applications from
accessing one."

Now 5 is a very small number, and easily exhausted by a View which creates a
few Fonts when painting. For example if we modify the
HelloWorld>>onPaintRequired: method to include a loop as follows:

onPaintRequired: aPaintEvent
    ...."as before"...
    2 to: 20 by: 2 do: [:p |
        canvas font: (Font name: 'Arial' pointSize: p)

And then do a 'HelloWorld show', at least one of the Hello messages will be
painted on the desktop (on Windows 95/98).

This is very easily fixed as follows:

Font>>initialize
    | dc |
    super initialize.
    (logfont := LOGFONT new) lfWeight: FW_NORMAL.
    dc := Canvas forDesktop.
    resolution := dc resolution.
    dc free

Running the same HelloWorld test now will work as expected.

Bill has quite rightly pointed out to me that it might be an idea to cache
the resolution for the sake of efficiency, and indeed it takes about 250
microseconds on a P133 running Win98 to retrieve the desktop resolution each
time. If one were creating a lot of Fonts, then this might be significant,
so when we patch Font>>initialize via LiveUpdate we will do just that. In
the meantime the attached at least leaves the desktop pristine!

Quote:
>....
> > The part I don't understand is why Win9x machines draw all over the
> desktop,
> > why they don't seem to crash as a result, and why the behavior is so
> > consitent.  Did you also find that it tended to do the same thing
> every
> > time?

> Yes, it was pretty consistent. However, I noticed that it painted all
> over the desktop, and then also on the canvas, correctly, at times...oh
> well.

Explained by the above I think?

Regards

Blair

begin 666 Font_initialize.st





M;W)I97-&;W(Z("-I;FET:6%L:7IE(6EN:71I86QI>FEN9R%P=6)L:6,A("$-

`
end



Thu, 11 Sep 2003 18:38:23 GMT  
 4.01 - Graphics Problem with Windows 98 but not NT or 2000
Blair -

Quote:
> > Yes, it was pretty consistent. However, I noticed that it painted all
> > over the desktop, and then also on the canvas, correctly, at times...oh
> > well.

> Explained by the above I think?

Perfectly

- Ken



Thu, 11 Sep 2003 20:36:35 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. was Re: 4.01Graphics Problem with Windows 98 but not NT or 2000

2. AdaGIDE 7.00 release (Ada GUI IDE for Windows 95,98,ME,NT,2000,XP)

3. Moving from Windows 98 to Windows 2000

4. A custom built DLL crashes labview 5.1 in windows 2000 but worked fine in windows 98

5. Help of Fortran 77 in Windows 98 and Windows 2000 or XP.

6. 95/98/nt/2000/me

7. desktops on 95/98/NT/2000

8. PL/I compiler for win 98 or Windows 2000

9. cobol error 98 in WIndows 2000

10. problem: mbp Cobol & Windows 98/NT

11. How to print in Windows 98/2000

12. Problem with Clarion5 legacy exe and windows NT/2000

 

 
Powered by phpBB® Forum Software