summary history branches tags files
commit:36e83259a5aca226db1fef68a93b35f7f64c7a39
author:Trevor Bentley
committer:Trevor Bentley
date:Thu Nov 16 22:34:09 2017 +0100
parents:d0317154c8e3ef3f5fe69d229decea3cbe2a3ce8
Fix crash when the selected item disappears from a scrubber
diff --git a/Cargo.toml b/Cargo.toml
line changes: +1/-1
index b711498..ffba85f
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -31,7 +31,7 @@ objc-foundation = "0.1.1"
 objc_id = "0.1"
 
 [dependencies.fruitbasket]
-version = "0.4"
+version = "0.5"
 features = ["logging"]
 
 [target."cfg(target_os = \"macos\")".dependencies.objc]

diff --git a/src/touchbar.rs b/src/touchbar.rs
line changes: +3/-1
index b26ddd1..90c8cf5
--- a/src/touchbar.rs
+++ b/src/touchbar.rs
@@ -783,9 +783,11 @@ impl TTouchbar for Touchbar {
             let item = *scrub_id as *mut Object;
             let scrubber: *mut Object = msg_send![item, view];
             let sel_idx: i32 = msg_send![scrubber, selectedIndex];
+            let pre_count: i32 = msg_send![scrubber, numberOfItems];
             let _:() = msg_send![scrubber, reloadData];
+            let post_count: i32 = msg_send![scrubber, numberOfItems];
             // reload clears the selected item.  re-select it.
-            if sel_idx >= 0 {
+            if sel_idx >= 0 && pre_count == post_count {
                 let _:() = msg_send![scrubber, setSelectedIndex: sel_idx];
             }
         }