Browse Source

fix assertion error after long delay

David Rose 15 years ago
parent
commit
57f10c8a37
1 changed files with 17 additions and 4 deletions
  1. 17 4
      panda/src/pipeline/threadSimpleManager.cxx

+ 17 - 4
panda/src/pipeline/threadSimpleManager.cxx

@@ -588,8 +588,15 @@ choose_next_context(struct ThreadContext *from_context) {
           }
           TickRecord &record = _tick_records.front();
           _total_ticks -= record._tick_count;
-          nassertv(record._thread->_run_ticks >= record._tick_count);
-          record._thread->_run_ticks -= record._tick_count;
+
+          if (record._thread->_run_ticks >= record._tick_count) {
+            // Ensure we don't go negative.
+            record._thread->_run_ticks -= record._tick_count;
+          } else {
+            // It is possible for this to happen if the application has been
+            // paused for more than 2^31 ticks.
+            record._thread->_run_ticks = 0;
+          }
           _tick_records.pop_front();
         }
         new_epoch = true;
@@ -724,8 +731,14 @@ do_timeslice_accounting(ThreadSimpleImpl *thread, double now) {
     nassertv(!_tick_records.empty());
     TickRecord &record = _tick_records.front();
     _total_ticks -= record._tick_count;
-    nassertv(record._thread->_run_ticks >= record._tick_count);
-    record._thread->_run_ticks -= record._tick_count;
+    if (record._thread->_run_ticks >= record._tick_count) {
+      // Ensure we don't go negative.
+      record._thread->_run_ticks -= record._tick_count;
+    } else {
+      // It is possible for this to happen if the application has been
+      // paused for more than 2^31 ticks.
+      record._thread->_run_ticks = 0;
+    }
     _tick_records.pop_front();
   }