pstats: Fix off-by-one error in frame number counting

The frame number for CPU frames was one ahead of the real one, which did show up correctly for GPU frames
This commit is contained in:
rdb 2022-12-07 14:42:29 +01:00
parent 5032d41f43
commit 9784d46e95

View File

@ -414,8 +414,9 @@ client_main_tick() {
for (vector_int::const_iterator vi = indices.begin();
vi != indices.end();
++vi) {
int frame_number = clock->get_frame_count(get_thread_object(*vi));
_impl->new_frame(*vi, frame_number);
InternalThread *thread = get_thread_ptr(*vi);
_impl->new_frame(*vi, thread->_frame_number);
thread->_frame_number = clock->get_frame_count(get_thread_object(*vi));
}
}
}
@ -678,12 +679,17 @@ do_make_thread(Thread *thread) {
int index = (*vi);
nassertr(index >= 0 && index < get_num_threads(), PStatThread());
ThreadPointer *threads = _threads.load(std::memory_order_relaxed);
if (threads[index]->_thread.was_deleted() &&
threads[index]->_sync_name == thread->get_sync_name()) {
InternalThread *pthread = threads[index];
if (pthread->_thread.was_deleted() &&
pthread->_sync_name == thread->get_sync_name()) {
// Yes, re-use this one.
threads[index]->_thread = thread;
pthread->_thread = thread;
thread->set_pstats_index(index);
thread->set_pstats_callback(this);
if (pthread->_sync_name == "Main") {
ClockObject *clock = ClockObject::get_global_clock();
pthread->_frame_number = clock->get_frame_count(thread);
}
return PStatThread(this, index);
}
}
@ -695,6 +701,10 @@ do_make_thread(Thread *thread) {
thread->set_pstats_callback(this);
InternalThread *pthread = new InternalThread(thread);
if (pthread->_sync_name == "Main") {
ClockObject *clock = ClockObject::get_global_clock();
pthread->_frame_number = clock->get_frame_count(thread);
}
add_thread(pthread);
return PStatThread(this, new_index);