Skip to content

Commit

Permalink
fix: Catch error when failed to release a player
Browse files Browse the repository at this point in the history
This happens when the user adds and removes the same video at a short interval of time
  • Loading branch information
bdlukaa committed Mar 3, 2024
1 parent 24e3b1f commit b9a9d9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ class _UnityAppState extends State<UnityApp>
await Future.microtask(() async {
for (final player in UnityVideoPlayerInterface.players.toList()) {
debugPrint('Disposing player ${player.hashCode}');
await player.dispose();
try {
await player.dispose();
} catch (e) {
debugPrint('Error disposing player: $e');
}
}
});
windowManager.destroy();
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ class UnityPlayers with ChangeNotifier {
static Future<void> releaseDevice(String deviceUUID) async {
debugPrint('Releasing device $deviceUUID. ${players[deviceUUID]}');
_reloadable.remove(deviceUUID);
await players[deviceUUID]?.dispose();
try {
await players[deviceUUID]?.dispose();
} catch (e) {
debugPrint('Error disposing player: $e');
}
players.remove(deviceUUID);
}

Expand Down

0 comments on commit b9a9d9a

Please sign in to comment.