NicoG60 / OscMackieControl

Utility bridge from Mackie Control to OSC
MIT License
27 stars 7 forks source link

Crash on OSC Messages without a value #5

Closed Sevenfold closed 4 years ago

Sevenfold commented 4 years ago

This app is amazing! It's making it possible to retire my physical controller. Everything has been running solidly for days, except for a crash changing custom TouchOSC tabs.

Use case example: TouchOSC tabs that have a non-numeric OSC address, as in "/cubase" rather than "/1". This cause a crash whenever switching to that tab, since Translator::readOSC is expecting a value for any OSC message unless it is numeric.

Possible Fix: I was able to build with a simple change. Below is what is working for me so far, and I imagine a better solution would be possible:

diff --git a/src/Translator.cpp b/src/Translator.cpp
index 0c07bf0..490420a 100755
--- a/src/Translator.cpp
+++ b/src/Translator.cpp
@@ -425,8 +425,17 @@ void Translator::readOSC(QByteArray raw)
                return;

        int chan = oscAddr.right(1).toInt(); //if any, reading channel id
-       int val = static_cast<int>(msg->getValue(0)->toFloat()); //Read osc value
-       bool bVal = val != 0; //The boolean version of val
+       
+
+       int val = 0;
+       bool bVal = false;
+       
+       if(msg->getNumValues() > 0){
+               val = static_cast<int>(msg->getValue(0)->toFloat()); //Read osc value
+               bVal = val != 0; //The boolean version of val
+       }
+
+
NicoG60 commented 4 years ago

Hey man, nice find! your fix should do the trick yeah if you can make a pull request, I'll review and merge it.