From d28bed6ed29f9aeea901ccbec2c075367007fb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 20 Mar 2021 12:29:24 +0100 Subject: [PATCH 1/2] Schedule adding transforms on tablet changes Fixes `InvalidThreadForMutationException`s that pop up when disconnecting/reconnecting tablets during the game's operation. In those cases the value change callback executes from an OpenTabletDriver thread. --- .../Sections/Input/TabletAreaSelection.cs | 15 ++++++----- .../Settings/Sections/Input/TabletSettings.cs | 25 +++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs index df25668411..ecb8acce54 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletAreaSelection.cs @@ -125,17 +125,20 @@ namespace osu.Game.Overlays.Settings.Sections.Input }, true); tablet.BindTo(handler.Tablet); - tablet.BindValueChanged(val => - { - tabletContainer.Size = val.NewValue?.Size ?? Vector2.Zero; - tabletName.Text = val.NewValue?.Name ?? string.Empty; - checkBounds(); - }, true); + tablet.BindValueChanged(_ => Scheduler.AddOnce(updateTabletDetails)); + updateTabletDetails(); // initial animation should be instant. FinishTransforms(true); } + private void updateTabletDetails() + { + tabletContainer.Size = tablet.Value?.Size ?? Vector2.Zero; + tabletName.Text = tablet.Value?.Name ?? string.Empty; + checkBounds(); + } + private static int greatestCommonDivider(int a, int b) { while (b != 0) diff --git a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs index b06b148984..4baf43783d 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs @@ -196,19 +196,13 @@ namespace osu.Game.Overlays.Settings.Sections.Input tablet.BindTo(tabletHandler.Tablet); tablet.BindValueChanged(val => { + Scheduler.AddOnce(toggleVisibility); + var tab = val.NewValue; bool tabletFound = tab != null; - if (!tabletFound) - { - mainSettings.Hide(); - noTabletMessage.Show(); return; - } - - mainSettings.Show(); - noTabletMessage.Hide(); offsetX.MaxValue = tab.Size.X; offsetX.Default = tab.Size.X / 2; @@ -222,6 +216,21 @@ namespace osu.Game.Overlays.Settings.Sections.Input }, true); } + private void toggleVisibility() + { + bool tabletFound = tablet.Value != null; + + if (!tabletFound) + { + mainSettings.Hide(); + noTabletMessage.Show(); + return; + } + + mainSettings.Show(); + noTabletMessage.Hide(); + } + private void applyAspectRatio(BindableNumber sizeChanged) { try From 86b569f5f7a13700b7ef728fafb6fe1c014ea8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 20 Mar 2021 12:34:41 +0100 Subject: [PATCH 2/2] Fix typo in identifier --- osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs index 4baf43783d..bd0f7ddc4c 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/TabletSettings.cs @@ -237,7 +237,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input { if (!aspectLock.Value) { - float proposedAspectRatio = curentAspectRatio; + float proposedAspectRatio = currentAspectRatio; if (proposedAspectRatio >= aspectRatio.MinValue && proposedAspectRatio <= aspectRatio.MaxValue) { @@ -278,8 +278,8 @@ namespace osu.Game.Overlays.Settings.Sections.Input aspectLock.Value = true; } - private void updateAspectRatio() => aspectRatio.Value = curentAspectRatio; + private void updateAspectRatio() => aspectRatio.Value = currentAspectRatio; - private float curentAspectRatio => sizeX.Value / sizeY.Value; + private float currentAspectRatio => sizeX.Value / sizeY.Value; } }