Subject: bug#33294: xwidget-insert crashes Emacs

From: Robert Pluim <[email-masked]>
Date: Mon, 26 Nov 2018 15:02:21 +0100

Eli Zaretskii <[email-masked]> writes:

>> Than this is a separate problem.  Looks like we need some flag to know
>> whether GTK has been initiaized (set in xg_initialize), and if not,
>> error out of make-xwidget and maybe xwidget_init_view.
>> 
>> I don't have access to an Emacs with xwidget support to test this; can
>> someone please provide a patch for that?

Something like this? (with ChangeLog etc of course). I couldn't come
up with a test-case for the xwidget_init_view path, but it causes
make-xwidget to error out under '-nw'

Robert

diff --git c/src/gtkutil.c i/src/gtkutil.c
index da4a0ae13d..4e4c953da2 100644
--- c/src/gtkutil.c
+++ i/src/gtkutil.c
@@ -5321,6 +5321,8 @@ xg_initialize (void)
 #ifdef HAVE_FREETYPE
   x_last_font_name = NULL;
 #endif
+
+  xg_gtk_initialized = true;
 }
 
 #endif /* USE_GTK */
diff --git c/src/gtkutil.h i/src/gtkutil.h
index 7dcd549f5c..3b074073e4 100644
--- c/src/gtkutil.h
+++ i/src/gtkutil.h
@@ -202,5 +202,6 @@ extern void xg_initialize (void);
    to indicate that the callback should do nothing.  */
 extern bool xg_ignore_gtk_scrollbar;
 
+extern bool xg_gtk_initialized;
 #endif /* USE_GTK */
 #endif /* GTKUTIL_H */
diff --git c/src/xwidget.c i/src/xwidget.c
index 6faac10751..6da7a0bb3f 100644
--- c/src/xwidget.c
+++ i/src/xwidget.c
@@ -78,6 +78,8 @@ Returns the newly constructed xwidget, or nil if construction fails.  */)
    Lisp_Object title, Lisp_Object width, Lisp_Object height,
    Lisp_Object arguments, Lisp_Object buffer)
 {
+  if (!xg_gtk_initialized)
+    error ("make-xwidget: GTK has not been initialized");
   CHECK_SYMBOL (type);
   CHECK_FIXNAT (width);
   CHECK_FIXNAT (height);
@@ -513,6 +515,10 @@ xwidget_init_view (struct xwidget *xww,
                    struct glyph_string *s,
                    int x, int y)
 {
+
+  if (!xg_gtk_initialized)
+    error ("xwidget_init_view: GTK has not been initialized");
+
   struct xwidget_view *xv = allocate_xwidget_view ();
   Lisp_Object val;