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..0326aa7a 100644 --- a/test/plotting/test_plotting.jl +++ b/test/plotting/test_plotting.jl @@ -214,6 +214,22 @@ 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")) + makie_ext.display_named(fig, "Saved then shown") + @test fig.scene.current_screens == [makie_ext.SCREENS["Saved then shown"]] + finally + screen = pop!(makie_ext.SCREENS, "Saved then shown", nothing) + isnothing(screen) || close(screen) + 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])