-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential fixes for GtkMakieWidget instabillity #21
Comments
Thanks so much for digging into this. I'll play with your solutions this weekend. BTW I just submitted a PR to get things working with GLMakie 0.11. A PR would be really welcome, and if the non-piratical way to fix this is to submit a PR to GLMakie or ShaderAbstractions, I think that should be pursued. Early on I did have to submit one or two's PR's to GLMakie to get this package working. |
It looks like overriding
This removes the need for Maybe defining another
|
Im currently looking into when a context switch is triggered. I think the cleanest solution would be to somehow get Makie to only write to the openGL context in the What I've noticed is that currently, both Makies own renderloop and the Gtk render callback are enabled. Wouldn't it make more sense to only use one of them? |
If we overload function current_context()
isassigned(ACTIVE_OPENGL_CONTEXT) || error("No active context")
ctx = ACTIVE_OPENGL_CONTEXT[]
ctx === nothing && error("No active context")
is_current_context(ctx) || error("No active context")
return ctx
end it would probably also be good to set |
I just checked and GLMakie's |
I don't see a way of getting GTK to tell us when it's changed context. Right now the only time we know it's changed is when we ask if a particular context is current, or switch to one. I should look at where |
I'm slow, you're suggesting setting |
You are correct. I just assumed that because
Yeah I don't know of any way either, but at least in Maybe in the end the solution would be to introduce ### in ShaderAbstractions
function current_context()
isassigned(ACTIVE_OPENGL_CONTEXT) || error("No active context")
ctx = ACTIVE_OPENGL_CONTEXT[]
ctx === nothing && error("No active context")
if !native_is_current_context(ctx)
ACTIVE_OPENGL_CONTEXT[] = nothing
error("The current context has been changed without notifying ShaderAbstractions")
end
return ctx
end
function is_current_context(x)
ACTIVE_OPENGL_CONTEXT[] == x && native_is_current_context(x)
end
function native_is_current_context(x)
return true # default to true to avoid breaking libraries that don't overload this method
end
### in Gtk4Makie
function ShaderAbstractions.native_is_current_context(x::GtkGLMakie)
curr = Gtk4.G_.get_current()
curr === nothing && return false
Gtk4.G_.get_context(x) == curr
end
### somewhere else for GLFW
function ShaderAbstractions.native_is_current_context(x::GLFW.Window)
curr = GLFW.GetCurrentContext()
curr == GLFW.Window(C_NULL) && return false
x == curr
end To me that seems like a fairly rubust and generally aplicable solution |
However, I still think Makie must be writing to openGL outside of the |
Yeah e.g. when you add a scatter plot to an axis it must be using the current context to do something before Do you want to do a PR that fixes the "local" issues (i.e. preventing the need for Getting a fix into ShaderAbstractions may take more time and will involve further discussion of the right way to do this. |
I actually don't have access to the computer where the project is on right now because I'm somewhere else atm. I'll play around with the solution a bit to maybe reproduce the issues I had and will let you know once I'm confident wheter it works. |
Sounds good |
I wasn't able to reproduce any of of the Blocks disapearing or rendering incompletely with your fix. |
I took the time to really dig into the the cause for the instabillities with GtkMakieWidget, as using 'make_current' did not allways work for me.
I especially had the issue that some Blocks randomly dissapeared or rendered with missing elements.
I think the main cause for the crashes and general weird behaviour has to do with how 'ShaderAbstractions' handles the openGL context. The variable
ShaderAbstractions.ACTIVE_OPENGL_CONTEXT
keeps track of the openGL context manually and therefore becomes out of sync with the acutal context, when a context switch is triggered by Gtk. I've found two possible solutions to this problem. One is more intrusive and involves pirating functions from ShaderAbstractions but is generally more robust and allows for Gtk windows and GLMakie windows to be opened at the same time. The other is simpler and less intrusive but causes GLMakie windows to break when a Gtk window is open as well.The robust but with piracy solution:
The less intrusive but also less robust solution:
instead of defining
ShaderAbstractions.native_switch_context!(a::GtkGLMakie)
With both of these solutions, manually calling
make_current
is no longer neccesary. It's probably possible to removeall the other calls to
make_current
outside ofShaderAbstractions.native_switch_context!(a::GtkGLMakie)
within this package as well.I haven't set up a PR yet, as I've been experimentig with this im my own project, but I could do so tomorrow.
The text was updated successfully, but these errors were encountered: