Browse Source

pstats: Fix menus not updating in some conditions

Menus would only update properly if there was a strip chart open that would cause the PStatView to be updated

Calling `check_update()` in `new_collector()` doesn't work properly because the views haven't been updated there yet; calling `do_update()` there does work around it but I think the better fix is just to make sure we always update the view so that the `check_update()` (which is also called by `idle()`) works properly
rdb 1 year ago
parent
commit
a9f6e6fd8a

+ 2 - 5
pandatool/src/gtk-stats/gtkStatsMonitor.cxx

@@ -160,11 +160,6 @@ new_collector(int collector_index) {
   for (GtkStatsGraph *graph : _graphs) {
     graph->new_collector(collector_index);
   }
-
-  // We might need to update our menus.
-  for (GtkStatsChartMenu *chart_menu : _chart_menus) {
-    chart_menu->check_update();
-  }
 }
 
 /**
@@ -190,6 +185,8 @@ new_thread(int thread_index) {
  */
 void GtkStatsMonitor::
 new_data(int thread_index, int frame_number) {
+  PStatMonitor::new_data(thread_index, frame_number);
+
   for (GtkStatsGraph *graph : _graphs) {
     graph->new_data(thread_index, frame_number);
   }

+ 2 - 5
pandatool/src/mac-stats/macStatsMonitor.mm

@@ -174,11 +174,6 @@ new_collector(int collector_index) {
   for (MacStatsGraph *graph : _graphs) {
     graph->new_collector(collector_index);
   }
-
-  // We might need to update our menus.
-  for (MacStatsChartMenu *chart_menu : _chart_menus) {
-    chart_menu->check_update();
-  }
 }
 
 /**
@@ -204,6 +199,8 @@ new_thread(int thread_index) {
  */
 void MacStatsMonitor::
 new_data(int thread_index, int frame_number) {
+  PStatMonitor::new_data(thread_index, frame_number);
+
   for (MacStatsGraph *graph : _graphs) {
     graph->new_data(thread_index, frame_number);
   }

+ 16 - 1
pandatool/src/pstatserver/pStatMonitor.cxx

@@ -563,7 +563,22 @@ new_thread(int) {
  * data will facilitate this.
  */
 void PStatMonitor::
-new_data(int, int) {
+new_data(int thread_index, int frame_number) {
+  const PStatClientData *client_data = get_client_data();
+
+  // Don't bother to update the thread data until we know at least something
+  // about the collectors and threads.
+  if (client_data->get_num_collectors() != 0 &&
+      client_data->get_num_threads() != 0) {
+    PStatView &view = get_view(thread_index);
+    const PStatThreadData *thread_data = view.get_thread_data();
+    if (!thread_data->is_empty()) {
+      int latest = thread_data->get_latest_frame_number();
+      if (frame_number == latest) {
+        view.set_to_frame(thread_data->get_frame(frame_number));
+      }
+    }
+  }
 }
 
 /**

+ 2 - 5
pandatool/src/win-stats/winStatsMonitor.cxx

@@ -146,11 +146,6 @@ new_collector(int collector_index) {
   for (WinStatsGraph *graph : _graphs) {
     graph->new_collector(collector_index);
   }
-
-  // We might need to update our menus.
-  for (WinStatsChartMenu *chart_menu : _chart_menus) {
-    chart_menu->do_update();
-  }
 }
 
 /**
@@ -196,6 +191,8 @@ remove_thread(int thread_index) {
  */
 void WinStatsMonitor::
 new_data(int thread_index, int frame_number) {
+  PStatMonitor::new_data(thread_index, frame_number);
+
   for (WinStatsGraph *graph : _graphs) {
     graph->new_data(thread_index, frame_number);
   }