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
20 changes: 12 additions & 8 deletions src/core/hyprlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,20 @@ void CHyprlock::run() {

const auto DPY = m_sWaylandState.display;

// Wake threads so they observe m_bTerminate and exit; pending timers are dropped
m_sLoopState.timerEvent = true;
m_sLoopState.timerCV.notify_all();

pthread_kill(pollThr.native_handle(), SIGRTMIN);

g_pAuth->terminate();

// Wait for threads to exit before destroying globals to prevent
// use-after-free in timer callbacks referencing g_asyncResourceManager
pollThr.join();
timersThr.join();

// Now safe to destroy globals — no more timer callbacks can fire
m_sWaylandState = {};
dma = {};

Expand All @@ -465,14 +477,6 @@ void CHyprlock::run() {

wl_display_disconnect(DPY);

pthread_kill(pollThr.native_handle(), SIGRTMIN);

g_pAuth->terminate();

// wait for threads to exit cleanly to avoid a coredump
pollThr.join();
timersThr.join();

Debug::log(LOG, "Reached the end, exiting");
}

Expand Down
24 changes: 17 additions & 7 deletions src/renderer/AsyncResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,12 @@ bool CAsyncResourceManager::request(ResourceID id, const AWP<IWidget>& widget) {
if (m_assets[id].texture) {
// Asset already present. Dispatch the asset callback function.
const auto& TEXTURE = m_assets[id].texture;
if (widget)
widget->onAssetUpdate(id, TEXTURE);
if (auto w = widget.lock()) {
w->onAssetUpdate(id, TEXTURE);

// TODO: add a centalized mechanism to render in one place in the event loop to avoid duplicate render calls
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [](auto, auto) { g_pHyprlock->renderAllOutputs(); }, nullptr);
// TODO: add a centalized mechanism to render in one place in the event loop to avoid duplicate render calls
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [](auto, auto) { g_pHyprlock->renderAllOutputs(); }, nullptr);
}
} else if (widget) {
// Asset currently in-flight. Add the widget reference to in order for the callback to get dispatched later.
m_resourcesMutex.lock();
Expand All @@ -279,7 +280,16 @@ void CAsyncResourceManager::enqueue(ResourceID resourceID, const ASP<IAsyncResou
m_resourcesMutex.unlock();

resource->m_events.finished.listenStatic([resourceID]() {
g_pHyprlock->addTimer(std::chrono::milliseconds(0), [](auto, void* resourceID) { g_asyncResourceManager->onResourceFinished((size_t)resourceID); }, (void*)resourceID);
if (!g_pHyprlock)
return;

g_pHyprlock->addTimer(
std::chrono::milliseconds(0),
[](auto, void* resourceID) {
if (g_asyncResourceManager)
g_asyncResourceManager->onResourceFinished((size_t)resourceID);
},
(void*)resourceID);
});
}

Expand Down Expand Up @@ -331,8 +341,8 @@ void CAsyncResourceManager::onResourceFinished(ResourceID id) {
m_assets[id].texture = texture;

for (const auto& widget : WIDGETS) {
if (widget)
widget->onAssetUpdate(id, texture);
if (auto w = widget.lock())
w->onAssetUpdate(id, texture);
}

g_pHyprlock->renderAllOutputs();
Expand Down