fix assertion error after long delay

This commit is contained in:
David Rose 2010-09-22 14:31:42 +00:00
parent 55455a48c9
commit 57f10c8a37

View File

@ -588,8 +588,15 @@ choose_next_context(struct ThreadContext *from_context) {
} }
TickRecord &record = _tick_records.front(); TickRecord &record = _tick_records.front();
_total_ticks -= record._tick_count; _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(); _tick_records.pop_front();
} }
new_epoch = true; new_epoch = true;
@ -724,8 +731,14 @@ do_timeslice_accounting(ThreadSimpleImpl *thread, double now) {
nassertv(!_tick_records.empty()); nassertv(!_tick_records.empty());
TickRecord &record = _tick_records.front(); TickRecord &record = _tick_records.front();
_total_ticks -= record._tick_count; _total_ticks -= record._tick_count;
nassertv(record._thread->_run_ticks >= record._tick_count); if (record._thread->_run_ticks >= record._tick_count) {
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(); _tick_records.pop_front();
} }