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
> 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!
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?
> 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!