Be more tolerant to missing values or errors in io_config()
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Sun, 31 Jul 2016 21:43:15 +0000 (23:43 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Mon, 1 Aug 2016 07:46:20 +0000 (09:46 +0200)
libs/ardour/luaproc.cc

index b393a2e00d85db86aceb8686d4b39b962c5a5299..af5534e21ab71fba84e2ccd8eb70811bd67a363f 100644 (file)
@@ -388,11 +388,13 @@ LuaProc::can_support_io_configuration (const ChanCount& in, ChanCount& out, Chan
        const int preferred_out = out.n_audio ();
 
        for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
-               assert (i.value ().type () == LUA_TTABLE);
                luabridge::LuaRef io (i.value ());
+               if (!io.isTable()) {
+                       continue;
+               }
 
-               int possible_in = io["audio_in"];
-               int possible_out = io["audio_out"];
+               int possible_in = io["audio_in"].isNumber() ? io["audio_in"] : -1;
+               int possible_out = io["audio_out"].isNumber() ? io["audio_out"] : -1;
 
                // exact match
                if ((possible_in == audio_in) && (possible_out == preferred_out)) {
@@ -428,11 +430,13 @@ LuaProc::can_support_io_configuration (const ChanCount& in, ChanCount& out, Chan
 }
 
        for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
-               assert (i.value ().type () == LUA_TTABLE);
                luabridge::LuaRef io (i.value ());
+               if (!io.isTable()) {
+                       continue;
+               }
 
-               int possible_in = io["audio_in"];
-               int possible_out = io["audio_out"];
+               int possible_in = io["audio_in"].isNumber() ? io["audio_in"] : -1;
+               int possible_out = io["audio_out"].isNumber() ? io["audio_out"] : -1;
 
                if (possible_out == 0) {
                        if (possible_in == 0) {
@@ -563,11 +567,13 @@ LuaProc::can_support_io_configuration (const ChanCount& in, ChanCount& out, Chan
        if (!found && imprecise) {
                /* try harder */
                for (luabridge::Iterator i (iotable); !i.isNil (); ++i) {
-                       assert (i.value ().type () == LUA_TTABLE);
                        luabridge::LuaRef io (i.value ());
+                       if (!io.isTable()) {
+                               continue;
+                       }
 
-                       int possible_in = io["audio_in"];
-                       int possible_out = io["audio_out"];
+                       int possible_in = io["audio_in"].isNumber() ? io["audio_in"] : -1;
+                       int possible_out = io["audio_out"].isNumber() ? io["audio_out"] : -1;
 
                        if (possible_out == 0 && possible_in == 0 && _has_midi_output) {
                                assert (audio_in > 0); // no input is handled above