diff --git a/src/MpvNet/Player.cs b/src/MpvNet/Player.cs index 25310545..0a0ba118 100644 --- a/src/MpvNet/Player.cs +++ b/src/MpvNet/Player.cs @@ -192,13 +192,16 @@ public void Init(IntPtr formHandle, bool processCommandLine) public void Destroy() { - mpv_destroy(MainHandle); + // Destroy client handles before the core; destroying the core first + // leaves the client handle pointing at freed memory (use-after-destroy). mpv_destroy(Handle); foreach (var client in Clients) { mpv_destroy(client.Handle); } + + mpv_destroy(MainHandle); } public void ProcessProperty(string? name, string? value)