Skip to content

Conversation

@v-ein
Copy link
Collaborator

@v-ein v-ein commented Dec 14, 2025


name: Pull Request
about: Create a pull request to help us improve
title: Refcount mess in mvAddCallback() and mvRunCallback()
assignees: ''


Closes #2036

Description:
This fix looks remarkably similar to PR #2282 by @bzczb, who deserves recognition for finding all the hidden gems quirks and overall for great job on fixing the issue (trust me, this rabbit hole was deep). However, in fact this PR is the result of "parallel evolution" of my own fix, and therefore bears some differences, too. One of them is how callbacks in the queue are handled when their "parent" mvAppItem gets deleted - currently both fixes have some visible side effects in this case. I'm going to add yet another fix on top of this (as a separate PR but still the same release) and try to keep delete_item behavior backward compatible for most scenarios/users.

This PR also includes some changes that got mixed with it over time and I decided to bring them along rather than waste time trying to separate things:

Also, the PR fixes some other issues that are not directly related to reference counting but are related to the callback mechanism:

Concerning Areas:
After merging this PR, delete_item will behave a bit differently: if a callback for the item being deleted is running (including the case where you call dpg.delete_item(sender) from the callback), the item will be kept alive until the callback completes. All subsequent callbacks waiting in the queue will be thrown away, but the current callback will work as if the item never got deleted. Well, you won't be able to actually access the item, but it will prevent creation of another one with the same tag/UUID 😅.

I'm going to add yet another PR to reduce some unexpected side effects of this change in behavior.

…unbalanced INCREF/DECREF calls and prevents leaks and some other issues hoffstadt#2036
@v-ein v-ein requested a review from hoffstadt December 14, 2025 14:15
@hoffstadt hoffstadt merged commit 736a0b7 into hoffstadt:master Dec 15, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants