# Wx::Font.new fails in a Runtime Error

**URL:** <https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801>\
**Category:** wxRuby\
**Created:** [October 13, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801 "2008-10-13T14:43:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 13, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/1 "2008-10-13T14:43:16Z")

</div>

I can’t construct a Wx::Font object, because it leads to a Runtime  
Error,  
though it seems that I use it as per documentation of WxRuby.

Strangely, many mistakes lead to such an error instead of a verbose Ruby  
exception ☹

Could you please help me with this?  
Thanks a lot in advance.  
Please see the sample code below.

====================  
require ‘wx’

class TestFrame \< Wx::Frame  
def initialize()  
super(nil, -1, “CMD”)  
Wx::Font.new(12, Wx::Font::FONTFAMILY\_DECORATIVE)  
end  
end

class TestApp \< Wx::App  
def on\_init  
TestFrame.new().show()  
end  
end

# TestApp.new.main\_loop

Enviroment:  
Windows XP SP-2  
Ruby 1.8.6  
WxRuby 1.9.8

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 13, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/2 "2008-10-13T15:17:14Z")

</div>

ÐšÐ¸Ñ€Ð¸Ð»Ð» Ð›Ð¸Ñ…Ð¾Ð´ÐµÐ´Ð¾Ð² wrote:

> ```
> Wx::Font.new(12, Wx::Font::FONTFAMILY_DECORATIVE)
> 
> ```

Try replacing that line with:

Wx::Font.new(12, Wx::FONTFAMILY\_DECORATIVE, Wx::FONTSTYLE\_NORMAL,  
Wx::FONTWEIGHT\_NORMAL)

- andreas

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 13, 2008, 3:33pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/3 "2008-10-13T15:33:53Z")

</div>

That worked (but why? Aren’t there default values for the rest of the  
parameters?), but setting this font as the default style of TextCtrl  
leads  
to the same error:  
text = Wx::TextCtrl.new(self, -1, “text”, :style =\>  
Wx::TE\_RICH|Wx::TE\_RICH2|Wx::TE\_PROCESS\_ENTER|Wx::TE\_PROCESS\_TAB)  
font = Wx::Font.new(12, Wx::FONTFAMILY\_DECORATIVE,  
Wx::FONTSTYLE\_NORMAL,  
Wx::FONTWEIGHT\_NORMAL)  
text.set\_default\_style(Wx::TextAttr.new(font)) #This leads to  
error

By the way, why is it a Runtime threatening error, not an exception?

2008/10/13 Andreas GarnÃ¦s [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 13, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/4 "2008-10-13T16:17:21Z")

</div>

ÐšÐ¸Ñ€Ð¸Ð»Ð» Ð›Ð¸Ñ…Ð¾Ð´ÐµÐ´Ð¾Ð² wrote:

> Oops, sorry, that should be  
> text.set\_default\_style(Wx::TextAttr.new(Wx::BLACK,  
> Wx::WHITE, font))
> 
> OK, I understand, it works now, thanks for the hint!
> 
> But the main problem still exists: it is very hard to determine when you  
> use  
> wrong or incomplete method signature, when it just silently fails.Is it  
> some  
> configuration problem of mine or it is WxRuby feature?
> 
> 2008/10/13 ÐšÐ¸Ñ€Ð¸Ð»Ð» Ð›Ð¸Ñ…Ð¾Ð´ÐµÐ´Ð¾Ð² [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

I guess you just have to read the documentation very carefully. I get  
significantly better error messages on Ubuntu, however, eg:

> Wx::Font.new(20)  
> ArgumentError: Wrong arguments for overloaded method ‘wxFont.new’.  
> Possible C/C++ prototypes are:  
> wxFont.new()  
> wxFont.new(int pointSize, int family, int style, int weight, bool  
> const underline, wxString const &faceName, wxFontEncoding encoding)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 13, 2008, 3:44pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/5 "2008-10-13T15:44:27Z")

</div>

Oops, sorry, that should be  
text.set\_default\_style(Wx::TextAttr.new(Wx::BLACK,  
Wx::WHITE, font))

OK, I understand, it works now, thanks for the hint!

But the main problem still exists: it is very hard to determine when you  
use  
wrong or incomplete method signature, when it just silently fails.Is it  
some  
configuration problem of mine or it is WxRuby feature?

2008/10/13 ÐšÐ¸Ñ€Ð¸Ð»Ð» Ð›Ð¸Ñ…Ð¾Ð´ÐµÐ´Ð¾Ð² [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 14, 2008, 9:30am UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/6 "2008-10-14T09:30:29Z")

</div>

Andreas, you definitely have much more descriptive messages.It looks  
like a  
problem of Windows version WxRuby, because Ruby itself doesn’t have  
these  
problems.

Does anybody know if anything can be done with it, maybe in future  
releases?

2008/10/13 Andreas GarnÃ¦s [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 25, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/7 "2008-10-25T15:47:01Z")

</div>

ÐšÐ¸Ñ€Ð¸Ð»Ð» Ð›Ð¸Ñ…Ð¾Ð´ÐµÐ´Ð¾Ð² wrote:

> Andreas, you definitely have much more descriptive messages.  
> It looks like a problem of Windows version WxRuby, because Ruby itself  
> doesn’t have these problems.
> 
> Does anybody know if anything can be done with it, maybe in future  
> releases?

The quality of error messages related to wrong types of arguments was  
improved in recent versions of SWIG. I’ll double-check that the next  
windows build is done with the latest version.

But when doing some development on Windows recently I had some similar  
problems - ie I was getting a segfault where it should be raising an  
exception. Which is pretty annoying b/c it’s hard to track these down.  
I’ll investigate further.

cheers  
alex

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 25, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/wx-font-new-fails-in-a-runtime-error/150801/8 "2008-10-25T23:08:40Z")

</div>

Thank you very much, Alex.

That would be very great if the problem will be fixed or at least  
improved. 🙂

25.10.2008, × 17:45, Alex F. ÎÁÐÉÓÁÌ(Á):
