@@ -2405,7 +2405,8 @@ namespace bgfx
24052405 if (_forceNewEncoder
24062406 || BGFX_API_THREAD_MAGIC != s_threadIndex)
24072407 {
2408- bx::MutexScope scopeLock (m_encoderApiLock);
2408+ bx::MutexScope beginLockScope (m_encoderBeginLock);
2409+ bx::MutexScope encoderApiScope (m_encoderApiLock);
24092410
24102411 uint16_t idx = m_encoderHandle->alloc ();
24112412 if (kInvalidHandle == idx)
@@ -2442,14 +2443,20 @@ namespace bgfx
24422443 m_encoder[0 ].end (true );
24432444
24442445#if BGFX_CONFIG_MULTITHREADED
2445- bx::MutexScope resourceApiScope (m_resourceApiLock);
2446-
2447- encoderApiWait ();
2446+ m_encoderBeginLock.lock (); // don't let any bgfx::begin calls...
2447+ encoderApiWait (); // wait for all started encoders to return...
24482448 bx::MutexScope encoderApiScope (m_encoderApiLock);
2449+ m_encoderBeginLock.unlock ();
2450+
2451+ bx::MutexScope resourceApiScope (m_resourceApiLock);
24492452#else
24502453 encoderApiWait ();
24512454#endif // BGFX_CONFIG_MULTITHREADED
24522455
2456+ m_encoderHandle->reset ();
2457+ const uint16_t idx = m_encoderHandle->alloc ();
2458+ BX_ASSERT (0 == idx, " Internal encoder handle is not 0 (idx %d)." , idx); BX_UNUSED (idx);
2459+
24532460 if (0 != (_flags & BGFX_FRAME_DISCARD) )
24542461 {
24552462 m_submit->m_numRenderItems = 0 ;
@@ -3344,7 +3351,7 @@ namespace bgfx
33443351 uint8_t skip;
33453352 _cmdbuf.read (skip);
33463353
3347- uintptr_t external;
3354+ uint64_t external;
33483355 _cmdbuf.read (external);
33493356
33503357 void * ptr = m_renderCtx->createTexture (handle, mem, flags, skip, external);
0 commit comments