Re: Fatal IO error 104 when using Gtk::Context::show_text
- From: Jonathon Jongsma <jonathon quotidian org>
- To: gtkmm-list gnome org
- Subject: Re: Fatal IO error 104 when using Gtk::Context::show_text
- Date: Fri, 16 Nov 2007 11:13:36 -0600
On Wed, 2007-11-14 at 01:48 -0800, Jake Brownson wrote:
> See below for a small program to recreate the problem.
>
> The window just flashes up and then I quickly get:
> "Fatal IO error 104 (Connection reset by peer) on X server :0.0."
>
> If I use a debugger the crash happens on the line with the show_text
> call, but I don't seem to get a signal, the app just crashes.
>
> I tried going through pango to draw text and see the same problem. I
> sent this to a friend (who runs the same distro and version I do) and
> he had the same problem. I also tried setting up all the font settings
> like in example code that comes with libcairomm, but that didn't seem
> to help.
>
> Am I doing something wrong? or is this a bug?
>
> I'm using Ubuntu 7.10, gtkmm 2.12.0, gtk 2.12.0, pango 1.18.3
>
> #include <gtkmm.h>
> #include <cairomm/cairomm.h>
>
> class CairoDrawer : public Gtk::DrawingArea
> {
> public:
> virtual bool on_expose_event(GdkEventExpose*)
> {
> Cairo::RefPtr<Cairo::Context> c = get_window()->create_cairo_context();
> Gtk::Allocation allocation = get_allocation();
> c->scale(allocation.get_width(), allocation.get_height());
> c->move_to(0, 0);
> c->show_text("Crash Here");
> return true;
> }
> };
>
> int main(int argc, char *argv[])
> {
> Gtk::Main kit(argc, argv);
> Gtk::Window window;
> CairoDrawer cairo_drawer;
> cairo_drawer.show();
> window.add(cairo_drawer);
As far as I can tell this is because when you call Cairo::scale(), it
doesn't seem to affect the font scale, so it is trying to draw a huge
font (e.g. the default font size of 10 or 12 multiplied by the size of
the window (~200), so it's trying to draw a font size of approximately
2000, and I guess X has problems with that). So you must explicitly set
the font size after scaling the context. But even with that, it
wouldn't show anything, because your move_to() sets the current point to
the top left corner of the window, and the call to show_text() will make
the text extend right and up, which will be outside of the boundary of
the window, so you need to change the move_to() so that the text gets
drawn within the window. The following code should work.
#include <gtkmm.h>
#include <cairomm/cairomm.h>
class CairoDrawer : public Gtk::DrawingArea
{
public:
virtual bool on_expose_event(GdkEventExpose*)
{
Cairo::RefPtr<Cairo::Context> c =
get_window()->create_cairo_context();
Gtk::Allocation allocation = get_allocation();
c->scale(allocation.get_width(),
allocation.get_height());
const double font_size = 0.05;
c->move_to(0, font_size);
c->set_font_size(font_size);
c->show_text("No Crash Here");
return true;
}
};
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
CairoDrawer cairo_drawer;
cairo_drawer.show();
window.add(cairo_drawer);
kit.run(window);
}
--
Jonner
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]