Skip to content

Commit 9908177

Browse files
authored
Fix GtkMakieWidget Crashes (#23)
1 parent 41b3aac commit 9908177

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ push!(p[2],scatter(rand(10)))
6060
show(win)
6161
```
6262

63-
The `push!` function adds a Makie `Figure` to the widget. Before modifying Makie plots in a callback, you **must** call `Gtk4.make_current` on the corresponding widget to ensure that the right OpenGL context will be modified. See the "widgets.jl" example for a demonstration of how to use the widget.
63+
The `push!` function adds a Makie `Figure` to the widget. Currently, using a `GtkMakieWidget` will likely break the rendering of any `GLFW` Windows (as for example used by standalone GLMakie) created by the same julia instance.
6464

6565
### Bonus functionality
6666

examples/interactive.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ g=grid(screen)
1818
g[1,2]=GtkButton("Generate new random plot")
1919

2020
function gen_cb(b)
21-
Gtk4.make_current(glarea(screen))
2221
empty!(ax)
2322
lines!(ax,rand(10))
2423
end

examples/widgets.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ push!(vbox, label, dropdown, new_scatter_button, clear_figure)
3838

3939
signal_connect(new_scatter_button, "clicked") do b
4040
plotnum = Gtk4.G_.get_selected(dropdown) + 1
41-
Gtk4.make_current(p[plotnum]) # it's critical to include this call -- otherwise GLMakie will not use the right GL context!
4241
scatter!(axes[plotnum], rand(100))
4342
end
4443

4544
signal_connect(clear_figure, "clicked") do b
4645
plotnum = Gtk4.G_.get_selected(dropdown) + 1
47-
Gtk4.make_current(p[plotnum]) # not clear this is needed
4846
empty!(axes[plotnum])
4947
end
5048

examples/widgets_extended.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ push!(vbox, GtkLabel("Select figure:"), dropdown, new_scatter_button, GtkLabel("
4141

4242
signal_connect(new_scatter_button, "clicked") do b
4343
plotnum = Gtk4.G_.get_selected(dropdown) + 1
44-
Gtk4.make_current(g[plotnum,1]) # it's critical to include this call -- otherwise GLMakie will not use the right GL context!
4544
scatter!(axes[plotnum], rand(100); label = Gtk4.text(entry))
4645
@idle_add Gtk4.model(g[plotnum,2], Gtk4Makie.plots_model(axes[plotnum])) # update the legend
4746
end
4847

4948
signal_connect(clear_figure, "clicked") do b
5049
plotnum = Gtk4.G_.get_selected(dropdown) + 1
51-
Gtk4.make_current(g[plotnum,1]) # not clear this is needed
5250
empty!(axes[plotnum])
5351
@idle_add Gtk4.model(g[plotnum,2], Gtk4Makie.plots_model(axes[plotnum])) # update the legend
5452
end

src/screen.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ end
197197
# overload this to get access to the figure
198198
function Base.display(screen::GLMakie.Screen{T}, figesque::Union{Makie.Figure,Makie.FigureAxisPlot}; update=true, display_attributes...) where T <: GtkWidget
199199
widget = glarea(screen)
200-
Gtk4.isrealized(widget) && Gtk4.make_current(widget) # required when pushing a figure to a widget well after it's realized
201200
fig = isa(figesque,Figure) ? figesque : figesque.figure
202201
if widget.figure != fig
203202
widget.inspector = nothing

src/widget.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ function ShaderAbstractions.native_switch_context!(a::GtkGLMakie)
2121
Gtk4.make_current(a)
2222
end
2323

24+
function ShaderAbstractions.is_current_context(a::GtkGLMakie)
25+
Gtk4.G_.get_realized(a) || return false
26+
a == ShaderAbstractions.ACTIVE_OPENGL_CONTEXT[] || return false
27+
curr = Gtk4.G_.get_current()
28+
return curr !== nothing && curr == Gtk4.G_.get_context(a)
29+
end
30+
2431
## Gtk4Makie overloads
2532

2633
glarea(screen::GLMakie.Screen{T}) where T <: GtkGLArea = screen.glscreen

0 commit comments

Comments
 (0)