fix: clean up power-resume timer on dispose and destroy

This commit is contained in:
edde746
2026-04-02 14:42:14 +02:00
parent 91db6d0e57
commit 29101c310b
+11
View File
@@ -57,6 +57,12 @@ MpvPlayerPlugin::MpvPlayerPlugin(flutter::PluginRegistrarWindows* registrar)
}
MpvPlayerPlugin::~MpvPlayerPlugin() {
// Clear power-resume callback and kill pending timer so they cannot
// invoke a dangling `this`.
if (MpvCore::GetInstance()) {
MpvCore::GetInstance()->SetPowerResumeCallback(nullptr);
::KillTimer(GetWindow(), MpvCore::kPowerResumeTimerId);
}
// Unregister window proc delegate.
if (proc_id_) {
registrar_->UnregisterTopLevelWindowProcDelegate(proc_id_.value());
@@ -139,6 +145,11 @@ void MpvPlayerPlugin::HandleMethodCall(
result->Error("INIT_FAILED", "Failed to initialize MPV player");
}
} else if (method == "dispose") {
// Clear power-resume callback and kill pending timer before disposing.
if (MpvCore::GetInstance()) {
MpvCore::GetInstance()->SetPowerResumeCallback(nullptr);
::KillTimer(GetWindow(), MpvCore::kPowerResumeTimerId);
}
if (player_) {
auto hwnd = player_->GetHwnd();
player_->Dispose();