From 3c8fb01dbeab0b0807478a010ed5662dec651a02 Mon Sep 17 00:00:00 2001 From: 1-Bort-1 <323661610+1-Bort-1@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:57:44 +0200 Subject: [PATCH 1/2] save_plot closes the screen Makie's save opened, so a saved figure can be shown Under GLMakie, save attaches the figure's scene to a hidden screen and leaves it there; show_plot then opened a titled screen and GLMakie threw 'can not display a scene in multiple Screens'. Fixes every plot function with is_save and is_show. Co-Authored-By: Claude Opus 5.5 --- ...98-plot-functions-throw-under-glmakie-when-.md | 3 +++ ext/VortexStepMethodMakieExt.jl | 4 ++++ test/plotting/test_plotting.jl | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 changelog.d/398-plot-functions-throw-under-glmakie-when-.md diff --git a/changelog.d/398-plot-functions-throw-under-glmakie-when-.md b/changelog.d/398-plot-functions-throw-under-glmakie-when-.md new file mode 100644 index 00000000..c74c5069 --- /dev/null +++ b/changelog.d/398-plot-functions-throw-under-glmakie-when-.md @@ -0,0 +1,3 @@ +### Fixed + +- Under GLMakie, a plot function called with `is_save=true, is_show=true` no longer throws `GLMakie can not display a scene in multiple Screens`: `save_plot` closes the hidden screen the save opened. diff --git a/ext/VortexStepMethodMakieExt.jl b/ext/VortexStepMethodMakieExt.jl index 3ca5b5ff..23a5a18b 100644 --- a/ext/VortexStepMethodMakieExt.jl +++ b/ext/VortexStepMethodMakieExt.jl @@ -486,6 +486,7 @@ function VortexStepMethod.save_plot(fig::Makie.Figure, save_path, title; data_ty @debug "Attempting to save figure to: $full_path" @debug "Current working directory: $(pwd())" + screens_before_save = copy(fig.scene.current_screens) try save(full_path, fig) @debug "Figure saved as $data_type" @@ -508,6 +509,9 @@ function VortexStepMethod.save_plot(fig::Makie.Figure, save_path, title; data_ty @error "Error saving figure: $e" @error "Error type: $(typeof(e))" rethrow(e) + finally + # GLMakie refuses to show a figure still held by the hidden screen `save` opened. + foreach(close, setdiff(fig.scene.current_screens, screens_before_save)) end end diff --git a/test/plotting/test_plotting.jl b/test/plotting/test_plotting.jl index 5c4b2f58..bba2cf22 100644 --- a/test/plotting/test_plotting.jl +++ b/test/plotting/test_plotting.jl @@ -214,6 +214,21 @@ end @test isfile(joinpath(save_dir, "Hidden_combined.png")) end + @testset "a plot saved under GLMakie can then be shown" begin + MakieControlPlots.GLMakie.activate!() + try + fig = plot_distribution([y_coordinates], [results_vsm], ["VSM"]; + title="Saved then shown", data_type=".png", save_path=save_dir, + is_save=true, is_show=false) + @test isfile(joinpath(save_dir, "Saved_then_shown.png")) + @test makie_ext.display_named(fig, "Saved then shown") === fig + finally + foreach(close, values(makie_ext.SCREENS)) + empty!(makie_ext.SCREENS) + CairoMakie.activate!() + end + end + @testset "round-off CS plots flat, a varying CS keeps its autoscale" begin fig = Figure() ax_noise = Axis(fig[1, 1]) From b625f4a0cccb8a51d0a8ec155e27ac16e678afd6 Mon Sep 17 00:00:00 2001 From: 1-Bort-1 <323661610+1-Bort-1@users.noreply.github.com> Date: Wed, 30 Sep 2026 15:03:24 +0200 Subject: [PATCH 2/2] GLMakie save-then-show test checks the scene sits on the titled screen alone Asserting display_named returns fig held on every path; checking current_screens also fails if display_named falls back to a bare display. Cleanup closes only the window this test opened. Co-Authored-By: Claude Opus 5.5 --- test/plotting/test_plotting.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/plotting/test_plotting.jl b/test/plotting/test_plotting.jl index bba2cf22..0326aa7a 100644 --- a/test/plotting/test_plotting.jl +++ b/test/plotting/test_plotting.jl @@ -221,10 +221,11 @@ end title="Saved then shown", data_type=".png", save_path=save_dir, is_save=true, is_show=false) @test isfile(joinpath(save_dir, "Saved_then_shown.png")) - @test makie_ext.display_named(fig, "Saved then shown") === fig + makie_ext.display_named(fig, "Saved then shown") + @test fig.scene.current_screens == [makie_ext.SCREENS["Saved then shown"]] finally - foreach(close, values(makie_ext.SCREENS)) - empty!(makie_ext.SCREENS) + screen = pop!(makie_ext.SCREENS, "Saved then shown", nothing) + isnothing(screen) || close(screen) CairoMakie.activate!() end end