Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nilcompiler/src/ui_runtime_appkit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ void dispose() noexcept {
if (!impl_) return;
auto old = std::move(impl_);
old->active.store(false);
if (old->owner == std::this_thread::get_id() && pthread_main_np()) old->dispose();
// A context can only be used on the main thread, so an owning thread that
// matches is already the main thread; testing for it again only risked
// deferring a disposal the other providers perform immediately.
if (old->owner == std::this_thread::get_id()) old->dispose();
else if (!old->nodes.empty()) {
try { std::lock_guard<std::mutex> lock(Impl::deferred_mutex()); Impl::deferred().push_back(std::move(old)); }
catch (...) { /* Callbacks hold no owning reference; a failed defer may leak windows, never free twice. */ }
Expand Down
18 changes: 15 additions & 3 deletions tests/ui_registry_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,21 @@ class UiRegistryObserver {
// than only that the numbers differed.
std::string detail() const {
#if defined(__APPLE__)
unsigned shown = 0;
for (NSWindow *window in NSApp.windows) if (window.visible) ++shown;
return " (listed " + std::to_string(listed()) + ", of those visible " + std::to_string(shown) + ")";
// Name every window still listed, with how many references are holding
// it, so a lingering one says whether the toolkit or an owner is keeping
// it alive. The fixture is compiled without ARC, so the count is readable.
std::string report = " (listed " + std::to_string(listed()) + ")";
for (NSWindow *window in NSApp.windows) {
const char *title = window.title.length ? window.title.UTF8String : "<untitled>";
const char *content = window.contentView
? NSStringFromClass([window.contentView class]).UTF8String : "<none>";
report += std::string("\n still listed: \"") + (title ? title : "?") + "\" content=" +
(content ? content : "?") +
" visible=" + (window.visible ? "1" : "0") +
" released_when_closed=" + (window.releasedWhenClosed ? "1" : "0") +
" refs=" + std::to_string(CFGetRetainCount((__bridge CFTypeRef)window));
}
return report;
#else
return " (observed " + std::to_string(count()) + ")";
#endif
Expand Down
Loading