diff --git a/src/platforms/atomic-kms/server/kms/atomic_kms_output.cpp b/src/platforms/atomic-kms/server/kms/atomic_kms_output.cpp index ef86b646f3..ccc5423440 100644 --- a/src/platforms/atomic-kms/server/kms/atomic_kms_output.cpp +++ b/src/platforms/atomic-kms/server/kms/atomic_kms_output.cpp @@ -350,17 +350,13 @@ bool mga::AtomicKMSOutput::has_crtc_mismatch() void mga::AtomicKMSOutput::clear_crtc() { auto conf = configuration.lock(); - try - { - ensure_crtc(*conf); - } - catch (...) + if (!conf->current_crtc) { /* * In order to actually clear the output, we need to have a crtc * connected to the output/connector so that we can disconnect - * it. However, not being able to get a crtc is OK, since it means - * that the output cannot be displaying anything anyway. + * it. However, if we don't have a current CRTC then we're obviously + * not displaying anything anyway. */ return; } diff --git a/src/platforms/atomic-kms/server/kms/display.cpp b/src/platforms/atomic-kms/server/kms/display.cpp index 377e3249df..3b9d5ca721 100644 --- a/src/platforms/atomic-kms/server/kms/display.cpp +++ b/src/platforms/atomic-kms/server/kms/display.cpp @@ -262,6 +262,8 @@ void mga::Display::clear_connected_unused_outputs() { current_display_configuration.for_each_output([&](DisplayConfigurationOutput const& conf_output) { + auto kms_output = current_display_configuration.get_output_for(conf_output.id); + /* * An output may be unused either because it's explicitly not used * (DisplayConfigurationOutput::used) or because its power mode is @@ -270,12 +272,21 @@ void mga::Display::clear_connected_unused_outputs() if (conf_output.connected && (!conf_output.used || (conf_output.power_mode != mir_power_mode_on))) { - auto kms_output = current_display_configuration.get_output_for(conf_output.id); - kms_output->clear_crtc(); kms_output->set_power_mode(conf_output.power_mode); kms_output->set_gamma(conf_output.gamma); } + /* + * If the output is no longer connected, we may still have associated resources + * with it. + * + * Clear those resources. + */ + if (!conf_output.connected) + { + // clear_crtc() is a no-op if there isn't an existing CRTC & we can't find one. + kms_output->clear_crtc(); + } }); }