core: fix crash on monitor removed with gammaControl (#7601)

* fix crash on monitor removed with gammaControl

* Update GammaControl.cpp
This commit is contained in:
Ikalco 2024-08-31 14:55:08 -05:00 committed by GitHub
parent cac59fefec
commit a6315b0af4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View file

@ -17,7 +17,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
return;
}
pMonitor = OUTPUTRES->monitor.get();
pMonitor = OUTPUTRES->monitor;
if (!pMonitor) {
LOGM(ERR, "No CMonitor");
@ -103,7 +103,7 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
resource->sendGammaSize(gammaSize);
listeners.monitorDestroy = pMonitor->events.destroy.registerListener([this](std::any) { this->onMonitorDestroy(); });
listeners.monitorDisconnect = pMonitor->events.destroy.registerListener([this](std::any) { this->onMonitorDestroy(); });
listeners.monitorDisconnect = pMonitor->events.disconnect.registerListener([this](std::any) { this->onMonitorDestroy(); });
}
CGammaControl::~CGammaControl() {
@ -119,7 +119,7 @@ bool CGammaControl::good() {
}
void CGammaControl::applyToMonitor() {
if (!pMonitor)
if (!pMonitor || !pMonitor->output)
return; // ??
LOGM(LOG, "setting to monitor {}", pMonitor->szName);
@ -136,16 +136,16 @@ void CGammaControl::applyToMonitor() {
pMonitor->output->state->setGammaLut({});
}
g_pHyprRenderer->damageMonitor(pMonitor);
g_pHyprRenderer->damageMonitor(pMonitor.get());
}
CMonitor* CGammaControl::getMonitor() {
return pMonitor;
return pMonitor ? pMonitor.get() : nullptr;
}
void CGammaControl::onMonitorDestroy() {
LOGM(LOG, "Destroying gamma control for {}", pMonitor->szName);
resource->sendFailed();
pMonitor = nullptr;
}
CGammaControlProtocol::CGammaControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {

View file

@ -20,7 +20,7 @@ class CGammaControl {
private:
SP<CZwlrGammaControlV1> resource;
CMonitor* pMonitor = nullptr;
WP<CMonitor> pMonitor;
size_t gammaSize = 0;
bool gammaTableSet = false;
std::vector<uint16_t> gammaTable; // [r,g,b]+