gtkd-developers / GtkD

GtkD is a D binding and OO wrapper of GTK+ originally created by Antonio Monteiro
http://gtkd.org
Other
322 stars 71 forks source link

PrintOperation.run() fails if it calls in fiber #190

Closed deviator closed 7 years ago

deviator commented 7 years ago

Hello. I write program on gtk-d and it's main loop (iterationDo(false)) runs in fiber and I have no problem with this and I thought printing is not a problem, but I was wrong. If run printing in fiber program fails. I think this code can show it.

void main()
{
    import core.thread;
    import gtk.Main;
    import cairo.Context;
    import gtk.PrintContext;
    import gtk.PrintOperation;
    import gtk.PrintSettings;
    string[] args;
    Main.init(args);

    bool work = true;

    void ff()
    {
        auto po = new PrintOperation;
        po.run(GtkPrintOperationAction.PRINT_DIALOG, null);
        work = false;
    }

    auto f = new Fiber(&ff);

    while (Main.iterationDo(false))
    {
        f.call(); // fails
        //ff(); // correctly run of printing dialog
        if (!work) break;
    }
}

gdb can't correctly detect place where code are failed. In my last reduced example it fails in gtk_css_style_provider_lookup, before I get stack trace in hex addresses

#0  0x0000000000000000 in  ()
#1  0x7463656a6f725000 in  ()
#2  0x737265562d64492d in  ()
#3  0x6b7467203a6e6f69 in  ()
#4  0x74726f7065520a2b in  ()
#5  0x422d646967734d2d in ()
...
#39 0x000000000a3b2931 in  ()
#40 0x0000000000000000 in  ()

and in a main program it fails in _int_malloc

#0  0x00007ffff6f4e1b9 in _int_malloc (av=av@entry=0x7ffff728bb00 <main_arena>, bytes=bytes@entry=12) at malloc.c:3347
#1  0x00007ffff6f500b0 in __GI___libc_malloc (bytes=12) at malloc.c:2911
#2  0x00007ffff6f5707a in __GI___strdup (s=0x121a720 "Lohit Hindi") at strdup.c:42
#3  0x00007ffff5ad5935 in IA__FcValueSave (v=...) at fcpat.c:103
#4  0x00007ffff5ac438c in FcConfigEvaluate (p=p@entry=0x15dac40, p_pat=p_pat@entry=0x0, kind=kind@entry=FcMatchPattern, e=0x13486e8) at fccfg.c:958
#5  0x00007ffff5ac4d42 in FcConfigValues
...
#62 0x00007ffff0d81f78 in pango_cairo_fc_font_map_fontset_key_substitute (fcfontmap=<optimized out>, fontkey=0x7ffff7ff4290, pattern=0x15dac40) at pangocairo-fcfontmap.c:111
#63 0x00007fffeee03f03 in pango_fc_font_map_load_fontset (pattern=<optimized out>, fontsetkey=0x7ffff7ff4290, fontmap=0x109bc30 [PangoCairoFcFontMap]) at pangofc-fontmap.c:1616
...
#129 0x00007fffedbb378e in gtk_widget_realize (widget=widget@entry=0x1494cf0 [GtkPrintUnixDialog]) at gtkwidget.c:5479
#130 0x00007fffedbc0bcb in gtk_window_show (widget=0x1494cf0 [GtkPrintUnixDialog]) at gtkwindow.c:6105
#134 0x00007ffff6a8143f in <emit signal ??? on instance 0x1494cf0 [GtkPrintUnixDialog]> (instance=instance@entry=0x1494cf0, signal_id=<optimized out>, detail=detail@entry=0)
    at gsignal.c:3441
    #131 0x00007ffff6a663e5 in g_closure_invoke (closure=closure@entry=0x108db30, return_value=return_value@entry=0x0, n_param_values=1, param_values=param_values@entry=0x7ffff7ff68e0, invocation_hint=invocation_hint@entry=0x7ffff7ff6860) at gclosure.c:804
    #132 0x00007ffff6a77e03 in signal_emit_unlocked_R (node=node@entry=0x108db80, detail=detail@entry=0, instance=instance@entry=0x1494cf0, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7ffff7ff68e0) at gsignal.c:3559
    #133 0x00007ffff6a8105f in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7ffff7ff6aa0) at gsignal.c:3385
#135 0x00007fffedbad4b2 in gtk_widget_show (widget=0x1494cf0 [GtkPrintUnixDialog]) at gtkwidget.c:4809
#136 0x00007fffed9d54e0 in gtk_dialog_run (dialog=dialog@entry=0x1494cf0 [GtkPrintUnixDialog]) at gtkdialog.c:1368
#137 0x00007fffedbddca3 in _gtk_print_operation_platform_backend_run_dialog (op=op@entry=0x10aa600 [GtkPrintOperation], show_dialog=<optimized out>, parent=parent@entry=0x10d8380 [GtkWindow], do_print=do_print@entry=0x7ffff7ff6c84) at gtkprintoperation-unix.c:870
#138 0x00007fffedab41f5 in gtk_print_operation_run (op=<optimized out>, action=<optimized out>, parent=<optimized out>, error=<optimized out>) at gtkprintoperation.c:3274
...

Maybe it's not a gtkd problem, but otherwise I do not know what might be the problem.

gtk-d 3.5.1 dub 1.2.0 dmd 2.073.2 linux 4.9.6-100 fc24 x86_64 gtk3.x86_64 3.20.10

MikeWey commented 7 years ago

I have the same issue, but with a different back trace. The fiber might be doing something that glib doesn't like, but i haven't found the problem yet.

deviator commented 7 years ago

I think it happens because size of fiber stack is fixed and staticaly allocated in fiber's ctor (by default 4*PAGESIZE). I tried increase it up to 64Kb and all works fine.

auto f = new Fiber(&ff, 1024*64);