From 7520147ff8d34d4e199b738437b4d27602a69b50 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 26 Jul 2021 09:12:29 +0200 Subject: [PATCH 1/3] ASUS - Keep local arrays of keys and lights in an attempt to fix crashes --- .../Generic/AsusUpdateQueue.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 77d4540..3075764 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -12,6 +12,9 @@ namespace RGB.NET.Devices.Asus { #region Properties & Fields + private readonly IAuraRgbLight[] _lights; + private readonly IAuraRgbKey[] _keys; + /// /// The device to be updated. /// @@ -29,6 +32,19 @@ namespace RGB.NET.Devices.Asus : base(updateTrigger) { this.Device = device; + + this._lights = new IAuraRgbLight[device.Lights.Count]; + for (int i = 0; i < device.Lights.Count; i++) + _lights[i] = device.Lights[i]; + + if (Device is IAuraSyncKeyboard keyboard) + { + this._keys = new IAuraRgbKey[keyboard.Keys.Count]; + for (int i = 0; i < keyboard.Keys.Count; i++) + _keys[i] = keyboard.Keys[i]; + } + else + this._keys = new IAuraRgbKey[0]; } #endregion @@ -42,7 +58,7 @@ namespace RGB.NET.Devices.Asus { if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { - if (Device is not IAuraSyncKeyboard keyboard) + if (Device is not IAuraSyncKeyboard) return; foreach ((object customData, Color value) in dataSet) @@ -50,7 +66,7 @@ namespace RGB.NET.Devices.Asus (AsusLedType ledType, int id) = (AsusKeyboardLedCustomData)customData; if (ledType == AsusLedType.Key) { - IAuraRgbLight light = keyboard.Key[(ushort)id]; + IAuraRgbLight light = _keys[(ushort)id]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; light.Green = g; @@ -58,7 +74,7 @@ namespace RGB.NET.Devices.Asus } else { - IAuraRgbLight light = keyboard.Lights[id]; + IAuraRgbLight light = _lights[id]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; light.Green = g; @@ -71,7 +87,7 @@ namespace RGB.NET.Devices.Asus foreach ((object key, Color value) in dataSet) { int index = (int)key; - IAuraRgbLight light = Device.Lights[index]; + IAuraRgbLight light = _lights[index]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; From 06f46811f4558bada00e7e668a9a9baef37aa183 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 26 Jul 2021 09:12:29 +0200 Subject: [PATCH 2/3] ASUS - Keep local arrays of keys and lights in an attempt to fix crashes --- .../Generic/AsusUpdateQueue.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index c4ce671..71507cf 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -12,6 +12,9 @@ namespace RGB.NET.Devices.Asus { #region Properties & Fields + private readonly IAuraRgbLight[] _lights; + private readonly IAuraRgbKey[] _keys; + /// /// The device to be updated. /// @@ -30,6 +33,19 @@ namespace RGB.NET.Devices.Asus : base(updateTrigger) { this.Device = device; + + this._lights = new IAuraRgbLight[device.Lights.Count]; + for (int i = 0; i < device.Lights.Count; i++) + _lights[i] = device.Lights[i]; + + if (Device is IAuraSyncKeyboard keyboard) + { + this._keys = new IAuraRgbKey[keyboard.Keys.Count]; + for (int i = 0; i < keyboard.Keys.Count; i++) + _keys[i] = keyboard.Keys[i]; + } + else + this._keys = new IAuraRgbKey[0]; } #endregion @@ -43,7 +59,7 @@ namespace RGB.NET.Devices.Asus { if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { - if (Device is not IAuraSyncKeyboard keyboard) + if (Device is not IAuraSyncKeyboard) return; foreach ((object customData, Color value) in dataSet) @@ -51,7 +67,7 @@ namespace RGB.NET.Devices.Asus (AsusLedType ledType, int id) = (AsusKeyboardLedCustomData)customData; if (ledType == AsusLedType.Key) { - IAuraRgbLight light = keyboard.Key[(ushort)id]; + IAuraRgbLight light = _keys[(ushort)id]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; light.Green = g; @@ -59,7 +75,7 @@ namespace RGB.NET.Devices.Asus } else { - IAuraRgbLight light = keyboard.Lights[id]; + IAuraRgbLight light = _lights[id]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; light.Green = g; @@ -72,7 +88,7 @@ namespace RGB.NET.Devices.Asus foreach ((object key, Color value) in dataSet) { int index = (int)key; - IAuraRgbLight light = Device.Lights[index]; + IAuraRgbLight light = _lights[index]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; From ecf880d297832566be048d9c0d8bc6ceacdf4792 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 3 Sep 2021 21:57:11 +0200 Subject: [PATCH 3/3] ASUS - Only keep local arrays of lights in an attempt to fix crashes --- RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 71507cf..241b354 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -13,7 +13,6 @@ namespace RGB.NET.Devices.Asus #region Properties & Fields private readonly IAuraRgbLight[] _lights; - private readonly IAuraRgbKey[] _keys; /// /// The device to be updated. @@ -37,15 +36,6 @@ namespace RGB.NET.Devices.Asus this._lights = new IAuraRgbLight[device.Lights.Count]; for (int i = 0; i < device.Lights.Count; i++) _lights[i] = device.Lights[i]; - - if (Device is IAuraSyncKeyboard keyboard) - { - this._keys = new IAuraRgbKey[keyboard.Keys.Count]; - for (int i = 0; i < keyboard.Keys.Count; i++) - _keys[i] = keyboard.Keys[i]; - } - else - this._keys = new IAuraRgbKey[0]; } #endregion @@ -59,7 +49,7 @@ namespace RGB.NET.Devices.Asus { if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { - if (Device is not IAuraSyncKeyboard) + if (Device is not IAuraSyncKeyboard keyboard) return; foreach ((object customData, Color value) in dataSet) @@ -67,7 +57,7 @@ namespace RGB.NET.Devices.Asus (AsusLedType ledType, int id) = (AsusKeyboardLedCustomData)customData; if (ledType == AsusLedType.Key) { - IAuraRgbLight light = _keys[(ushort)id]; + IAuraRgbLight light = keyboard.Key[(ushort)id]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; light.Green = g;