From d4dab05c5d27b727dfa9a1de4bf720f285a6b64f Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Wed, 11 Mar 2015 18:08:47 +0100
Subject: [PATCH] Fix channel indexing segfault

---
 Source/Processors/DataThreads/RHD2000Editor.cpp | 5 ++++-
 Source/Processors/DataThreads/RHD2000Thread.cpp | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/Source/Processors/DataThreads/RHD2000Editor.cpp b/Source/Processors/DataThreads/RHD2000Editor.cpp
index 8ebf2c5fa..30285b166 100644
--- a/Source/Processors/DataThreads/RHD2000Editor.cpp
+++ b/Source/Processors/DataThreads/RHD2000Editor.cpp
@@ -807,7 +807,6 @@ void RHD2000Editor::comboBoxChanged(ComboBox* comboBox)
 
 void RHD2000Editor::buttonEvent(Button* button)
 {
-    VisualizerEditor::buttonEvent(button);
     if (button == rescanButton && !acquisitionIsActive)
     {
         board->scanPorts();
@@ -848,6 +847,10 @@ void RHD2000Editor::buttonEvent(Button* button)
 	{
 		board->enableBoardLeds(button->getToggleState());
 	}
+	else
+	{
+		VisualizerEditor::buttonEvent(button);
+	}
 
 }
 
diff --git a/Source/Processors/DataThreads/RHD2000Thread.cpp b/Source/Processors/DataThreads/RHD2000Thread.cpp
index 7e176bd97..d5fdacfad 100644
--- a/Source/Processors/DataThreads/RHD2000Thread.cpp
+++ b/Source/Processors/DataThreads/RHD2000Thread.cpp
@@ -1644,8 +1644,8 @@ int RHD2000Thread::getChannelFromHeadstage(int hs, int ch)
                     if (i < hs)
                         hsCount++;
                 }
-                return channelCount + hsCount * 3 + ch;
             }
+			return channelCount + hsCount * 3 + ch-headstagesArray[hs]->getNumActiveChannels();
         }
         else
         {
-- 
GitLab