Skip to content

Commit cba4a8f

Browse files
authored
Allow gtk_init_check to fail (#86)
1 parent cc368c9 commit cba4a8f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Gtk4"
22
uuid = "9db2cae5-386f-4011-9d63-a5602296539b"
3-
version = "0.7.5"
3+
version = "0.7.6"
44

55
[deps]
66
BitFlags = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"

src/Gtk4.jl

+7-4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ function set_EGL_vendorlib_dirs(dirs)
136136
@info("Setting will take effect after restarting Julia.")
137137
end
138138

139+
const initialized = Ref(false) # whether `init_check` succeeded, not necessarily the same as GTK4's `is_initialized`
140+
139141
function __init__()
140142
in("Gtk",[x.name for x in keys(Base.loaded_modules)]) && error("Gtk4 is incompatible with Gtk.")
141143

@@ -186,8 +188,11 @@ function __init__()
186188
end
187189
end
188190

189-
success = ccall((:gtk_init_check, libgtk4), Cint, ()) != 0
190-
success || error("gtk_init_check() failed.")
191+
initialized[] = ccall((:gtk_init_check, libgtk4), Cint, ()) != 0
192+
if !initialized[]
193+
@warn("Gtk4 initialization failed. Calling Gtk4 methods will cause Julia to crash.")
194+
return
195+
end
191196

192197
if Sys.islinux() || Sys.isfreebsd()
193198
G_.set_default_icon_name("julia")
@@ -198,8 +203,6 @@ function __init__()
198203
GLib.G_.set_prgname("julia")
199204

200205
isinteractive() && GLib.start_main_loop()
201-
202-
#@debug("Gtk4 initialized.")
203206
end
204207

205208
isinitialized() = G_.is_initialized()

0 commit comments

Comments
 (0)