From 7b7bf9311842564375b4872c8b91da3a0d361c1c Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 12 Jul 2016 11:24:09 +0200 Subject: [PATCH] Fix frame chug when loading big model asynchronously (LP #1019599) --- doc/ReleaseNotes | 1 + panda/src/putil/bamCache.cxx | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/ReleaseNotes b/doc/ReleaseNotes index 3796b840c0..a4ca29a6cf 100644 --- a/doc/ReleaseNotes +++ b/doc/ReleaseNotes @@ -25,6 +25,7 @@ This issue fixes several bugs that were still found in 1.9.2. * Work around Cg bug generating invalid ASM for saturated tex loads * Fix issues with certain Cg shader inputs in DX9 * Support uint8 index buffers in DX9 +* Fix occasional frame lag when loading a big model asynchronously ------------------------ RELEASE 1.9.2 ------------------------ diff --git a/panda/src/putil/bamCache.cxx b/panda/src/putil/bamCache.cxx index 7616350e07..f0d04d08c8 100644 --- a/panda/src/putil/bamCache.cxx +++ b/panda/src/putil/bamCache.cxx @@ -321,13 +321,24 @@ emergency_read_only() { //////////////////////////////////////////////////////////////////// void BamCache:: consider_flush_index() { - ReMutexHolder holder(_lock); +#if defined(HAVE_THREADS) || defined(DEBUG_THREADS) + if (!_lock.try_acquire()) { + // If we can't grab the lock, no big deal. We don't want to hold up + // the frame waiting for a cache operation. We can try again later. + return; + } +#endif + if (_index_stale_since != 0) { int elapsed = (int)time(NULL) - (int)_index_stale_since; if (elapsed > _flush_time) { flush_index(); } } + +#if defined(HAVE_THREADS) || defined(DEBUG_THREADS) + _lock.release(); +#endif } ////////////////////////////////////////////////////////////////////