1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Fix for #225 and the crashes in #224

This commit is contained in:
SpoinkyNL 2016-12-15 11:12:35 +01:00
parent 9f8cbe46f0
commit 9e7ddfc51c

View File

@ -20,12 +20,14 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
internal class KeyPressType : ILayerType internal class KeyPressType : ILayerType
{ {
private readonly DeviceManager _deviceManager; private readonly DeviceManager _deviceManager;
private List<LayerModel> _keyPressLayers = new List<LayerModel>(); private List<LayerModel> _keyPressLayers;
private LayerModel _layerModel; private LayerModel _layerModel;
public KeyPressType(DeviceManager deviceManager) public KeyPressType(DeviceManager deviceManager)
{ {
_deviceManager = deviceManager; _deviceManager = deviceManager;
_keyPressLayers = new List<LayerModel>();
KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback; KeyboardHook.KeyDownCallback += KeyboardHookOnKeyDownCallback;
} }
@ -77,10 +79,12 @@ namespace Artemis.Profiles.Layers.Types.KeyPress
lock (_keyPressLayers) lock (_keyPressLayers)
{ {
// Remove expired key presses // Remove expired key presses
_keyPressLayers = _keyPressLayers.Where(k => !k.LayerAnimation.MustExpire(k)).ToList(); var updateLayers = _keyPressLayers.Where(k => !k.LayerAnimation.MustExpire(k)).ToList();
// Update the ones that are still active // Update the ones that are still active
foreach (var keyPressLayer in _keyPressLayers) foreach (var updateLayer in updateLayers)
keyPressLayer.Update(null, false, true); updateLayer.Update(null, false, true);
_keyPressLayers = updateLayers;
} }
} }