From bceca7701661650a7fc89ba523bc30854aa055c0 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 1 Nov 2018 17:09:40 -0500 Subject: [PATCH] Fix AutoLightsColorRefreshColor calling SetColor with an incomplete array. This could cause access violations, because it calls the native SMX_SetColor with a color array that's too small. --- smx-config/Helpers.cs | 10 +++++----- smx-config/SMX.cs | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/smx-config/Helpers.cs b/smx-config/Helpers.cs index 37331a8..a75c75a 100644 --- a/smx-config/Helpers.cs +++ b/smx-config/Helpers.cs @@ -320,16 +320,16 @@ namespace smx_config private void AutoLightsColorRefreshColor() { - byte[] lights = new byte[864]; CommandBuffer cmd = new CommandBuffer(); for(int pad = 0; pad < 2; ++pad) { + // Use this panel's color. If a panel isn't connected, we still need to run the + // loop below to insert data for the panel. + byte[] color = new byte[9*3]; SMX.SMXConfig config; - if(!SMX.SMX.GetConfig(pad, out config)) - continue; - - byte[] color = config.stepColor; + if(SMX.SMX.GetConfig(pad, out config)) + color = config.stepColor; for( int iPanel = 0; iPanel < 9; ++iPanel ) { for( int i = 0; i < 16; ++i ) diff --git a/smx-config/SMX.cs b/smx-config/SMX.cs index a6a70a7..0367bba 100644 --- a/smx-config/SMX.cs +++ b/smx-config/SMX.cs @@ -414,6 +414,9 @@ namespace SMX public static void SetLights(byte[] buf) { if(!DLLAvailable()) return; + + if(buf.Length != 9*16*3*2) + throw new Exception("SetLights buffer has an invalid length: " + buf.Length); SMX_SetLights(buf); }