[wxPython] Font.GetWeight()

Hi, I ran into this:

f = Dc.GetFont()
print f.GetWeight() <— Exception here

f.SetWeight(wxBOLD)


Dc.DrawText(self.Text, self.X, self.Y)

PYTHON verursachte einen Fehler durch eine ungültige Seite
in Modul WX22_2.DLL bei 017f:00f15c46.
Register:
EAX=00000000 CS=017f EIP=00f15c46 EFLGS=00010202
EBX=01730b4c SS=0187 ESP=0063f558 EBP=00000000
ECX=016d1fa8 DS=0187 ESI=00760870 FS=47e7
EDX=00f901b8 ES=0187 EDI=10054f70 GS=0000
Bytes bei CS:EIP:
8b 40 1c c3 8b 41 04 8a 40 20 c3 55 8b ec 51 a1
Stapelwerte:
10054fd7 10054f70 01727abc 016d114c 1022ee50 00000000 1e1128b2 00000000 01727abc 016d1fa8 1e1896c0 01727abc 00000000 1e112800 007d2180 01727abc

removing the GetWeight fixes the problem. I was trying to DrawText bold…

I also noticed that DrawRotated text does not rotate the text if the Weight has been modified…

Has anyone seen these, or maybe has a fix?

Roger

···

Probably because there is no font selected by default in a DC. I don't
know how Python code works but I guess that SetWeight() creates a new
font and calls DC.SetFont(), but if you just call GetWeight(), there is
no font to query - besides, it really doesn't make sense.

Regards,
VZ

···

On Wed, 14 Mar 2001, Roger Wenham wrote:

Hi, I ran into this:

  ......
  f = Dc.GetFont()
  print f.GetWeight() <--- Exception here

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

> Hi, I ran into this:
>
> ......
> f = Dc.GetFont()
> print f.GetWeight() <--- Exception here

Probably because there is no font selected by default in a DC.

Correct, almost. If you call f.Ok() here you get false, but there is a
wxFont object there.

I don't
know how Python code works but I guess that SetWeight() creates a new
font and calls DC.SetFont(),

No. Since GetFont returns a wxFont& then the Python f refers to a real
wxFont object. The DC's font is initialized to wxNullFont so the crash is
happening on a call to wxNullFont.GetWeight(). I havn't traced into it yet
but my guess it's on this line:

    return M_FONTDATA->m_weight;

What does M_FONTDATA evaluate to when it is wxNullFont? I agree that it
doesn't make sense to call the methods of a font if !Ok(), but it shouldn't
crash. Perhaps a wxASSERT should be put there (and in the other methods,)
and even in non-debug mode it should return a bogus value (-1 or something)
instead of just crashing...

···

On Wed, 14 Mar 2001, Roger Wenham wrote:

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

What does M_FONTDATA evaluate to when it is wxNullFont?

Considering that "bool Ok() const { return m_refData != NULL; }" it seems
logical that it crash - M_FONTDATA is just NULL.

I agree that it
doesn't make sense to call the methods of a font if !Ok(), but it shouldn't
crash.

The funny thing is that it shouldn't (from gtk/font.cpp):

int wxFont::GetWeight() const
{
    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );

    return M_FONTDATA->m_weight;
}

So it gives an assert failure (in debug mode only) and returns 0 if the
font is invalid.

Perhaps a wxASSERT should be put there (and in the other methods,)

wxASSERT would be useless, but wxCHECK is just right - it does exactly
what you say should be done. So I don't understand any more how the
original poster got a crash here. Maybe he used a debug mode build and
got a trace trap?

Regards,
VZ

···

On Thu, 15 Mar 2001, Robin Dunn wrote:

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

> I agree that it
> doesn't make sense to call the methods of a font if !Ok(), but it

shouldn't

> crash.

The funny thing is that it shouldn't (from gtk/font.cpp):

[...]

wxASSERT would be useless, but wxCHECK is just right - it does exactly
what you say should be done. So I don't understand any more how the
original poster got a crash here. Maybe he used a debug mode build and
got a trace trap?

Look in src/msw/font.cpp, there are no checks.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Hmm, the funny thing is that I was _sure_ that the OP was using wxGTK.
Don't know why though.

Anyhow, I've added the checks to the MSW version as well (main branch
only, although they can be merged back into 2.2 if someone really wants
them).

Regards,
VZ

···

On Thu, 15 Mar 2001, Robin Dunn wrote:

Look in src/msw/font.cpp, there are no checks.

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users