Skip to content
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

Make cleanup of OpenGL objects explicit in GLMakie #4699

Open
wants to merge 41 commits into
base: master
Choose a base branch
from

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Jan 2, 2025

Description

After some help from Simon we figured out that GC / free() was the cause of issues in #4689. Specifically because free() includes a context switch and GC can trigger it whenever via finalizers, context switches can occur randomly. To fix this I'm making all cleanup of OpenGL objects explicit here, i.e. remove the need for finalizers.

The current version should segfault if a finalizer deletes OpenGL objects. I'll let CI run with this so I can see if I missed anything Passed locally, should no longer segfault

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Added an entry in CHANGELOG.md (for new features and breaking changes)
  • Added or changed relevant sections in the documentation
  • Added unit tests for new algorithms, conversion methods, etc.
  • Added reference image tests for new plotting functions, recipes, visual options, etc.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Jan 2, 2025

@MakieBot
Copy link
Collaborator

MakieBot commented Jan 2, 2025

Benchmark Results

SHA: 667094d1cce35b3e850af13c5c78264005a20878

Warning

These results are subject to substantial noise because GitHub's CI runs on shared machines that are not ideally suited for benchmarking.

GLMakie
CairoMakie
WGLMakie

Comment on lines 101 to 108
const FAILED_FREE_COUNTER = Ref(0)

function verify_free(obj::T, name = string(T)) where T
if obj.id != 0
FAILED_FREE_COUNTER[] = FAILED_FREE_COUNTER[] + 1
Threads.@spawn println(stderr, "Error: $name has not been freed.")
end
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used as the finalizer now, to "error" when something hasn't been deleted. I also added a counter to query in CI. We could also de/activate that with an environment variable but I figured incrementing and integer doesn't really matter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:

string(T) seems to be pretty slow, should be moved so it only happens if the branch is true (dragged one of my benchmarks in #4689 from ~300µs down to 800µs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we want to completely disable finalizers and only activate them in debug mode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think registering a finalizer is somewhat expensive, so if we only use it for debugging purposes we should just disable it via a global ( not an env var)

@ffreyer ffreyer marked this pull request as ready for review January 3, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready to review
Development

Successfully merging this pull request may close these issues.

3 participants