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.
master
Glenn Maynard 6 years ago
parent 4c0da63842
commit bceca77016
  1. 10
      smx-config/Helpers.cs
  2. 3
      smx-config/SMX.cs

@ -320,16 +320,16 @@ namespace smx_config
private void AutoLightsColorRefreshColor() private void AutoLightsColorRefreshColor()
{ {
byte[] lights = new byte[864];
CommandBuffer cmd = new CommandBuffer(); CommandBuffer cmd = new CommandBuffer();
for(int pad = 0; pad < 2; ++pad) 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; SMX.SMXConfig config;
if(!SMX.SMX.GetConfig(pad, out config)) if(SMX.SMX.GetConfig(pad, out config))
continue; color = config.stepColor;
byte[] color = config.stepColor;
for( int iPanel = 0; iPanel < 9; ++iPanel ) for( int iPanel = 0; iPanel < 9; ++iPanel )
{ {
for( int i = 0; i < 16; ++i ) for( int i = 0; i < 16; ++i )

@ -414,6 +414,9 @@ namespace SMX
public static void SetLights(byte[] buf) public static void SetLights(byte[] buf)
{ {
if(!DLLAvailable()) return; if(!DLLAvailable()) return;
if(buf.Length != 9*16*3*2)
throw new Exception("SetLights buffer has an invalid length: " + buf.Length);
SMX_SetLights(buf); SMX_SetLights(buf);
} }

Loading…
Cancel
Save