Fix NV12 crash issue when recreate camera object
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <cstdint>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h> // Sleep()
|
||||
#endif
|
||||
#include <cstdio>
|
||||
|
||||
// ── Shared YUV→RGB computation ───────────────────────────────────────────
|
||||
@@ -651,7 +654,24 @@ int ANSGpuNV12ToBGR(
|
||||
width * 3, height,
|
||||
cudaMemcpyDeviceToHost, t_bufs.stream);
|
||||
|
||||
cudaStreamSynchronize(t_bufs.stream);
|
||||
// Use polling sync instead of cudaStreamSynchronize to avoid
|
||||
// holding nvcuda64 SRW lock continuously (WDDM deadlock prevention).
|
||||
// Short Sleep(0) fast path for sub-ms kernels, then Sleep(1) to give
|
||||
// cleanup operations (cuArrayDestroy, cuMemFree) a window to acquire
|
||||
// the exclusive SRW lock.
|
||||
{
|
||||
cudaError_t qerr = cudaStreamQuery(t_bufs.stream);
|
||||
if (qerr == cudaErrorNotReady) {
|
||||
for (int i = 0; i < 10 && qerr == cudaErrorNotReady; ++i) {
|
||||
Sleep(0);
|
||||
qerr = cudaStreamQuery(t_bufs.stream);
|
||||
}
|
||||
while (qerr == cudaErrorNotReady) {
|
||||
Sleep(1);
|
||||
qerr = cudaStreamQuery(t_bufs.stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for errors
|
||||
cudaError_t err = cudaGetLastError();
|
||||
|
||||
Reference in New Issue
Block a user