]> git.sesse.net Git - nageru/commitdiff
Fix saving of MIDI mappings with camera switch buttons that have no associated lights...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Apr 2019 20:27:12 +0000 (22:27 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 8 Apr 2019 20:27:12 +0000 (22:27 +0200)
This could cause invalid protobufs to be saved, causing assertion errors
when loading them back.

Reported by Niall Walsh.

futatabi/midi_mapping_dialog.cpp

index 6cd4b6e8e7441ae0cf3539c0cd9133f492251015..de393c38dacdbe2002de8c7441aa96d5e7402ddc 100644 (file)
@@ -293,23 +293,25 @@ unique_ptr<MIDIMappingProto> MIDIMappingDialog::construct_mapping_proto_from_ui(
        
                {       
                        const InstantiatedSpinner &is = camera_button_spinners[camera_idx];
-                       MIDIButtonProto *button_proto =
-                               get_mutable_message<MIDIButtonProto>(camera_proto, is.field_number);
                        int val = is.spinner->value();
                        if (val != -1) {
+                               MIDIButtonProto *button_proto =
+                                       get_mutable_message<MIDIButtonProto>(camera_proto, is.field_number);
                                button_proto->set_note_number(val);
                        }
                }
                {       
                        const InstantiatedSpinner &is = camera_button_light_spinners[camera_idx];
+                       int val = is.spinner->value();
+                       int val2 = is.spinner2->value();
+
+                       if (val == -1 && val2 == -1) continue;
+
                        MIDILightProto *light_proto =
                                get_mutable_message<MIDILightProto>(camera_proto, is.field_number);
-                       int val = is.spinner->value();
                        if (val != -1) {
                                light_proto->set_note_number(val);
                        }
-
-                       int val2 = is.spinner2->value();
                        if (val2 != -1) {
                                light_proto->set_velocity(val2);
                        }