Unity-Technologies / com.unity.webrtc

WebRTC package for Unity
Other
738 stars 185 forks source link

fix: checks for DLLs before calling NvEncoder APIs #987

Closed DannisMa closed 9 months ago

DannisMa commented 9 months ago

Some CUDA platforms do not support NvEncoder, so using the relevant API without confirmation will cause a crash. https://github.com/Unity-Technologies/com.unity.webrtc/issues/806 I referred to Nvidia's GitHub project, we can see that it checks for DLLs before calling NvEncoder APIs. https://github.com/NVIDIA/video-sdk-samples/blob/aa3544dcea2fe63122e4feb83bf805ea40e58dbe/Samples/NvCodec/NvEncoder/NvEncoder.cpp#L58

unity-cla-assistant commented 9 months ago

CLA assistant check
All committers have signed the CLA.

karasusan commented 9 months ago

DLL check is already here.

https://github.com/Unity-Technologies/com.unity.webrtc/blob/74627ff217019b11936c2eba016f876276b52d33/Plugin~/WebRTCPlugin/GraphicsDevice/Cuda/CudaContext.cpp#L34-L59

Can you tell me when you have a crash?

DannisMa commented 9 months ago

Maybe you should also check for the presence of 'nvEncodeAPI64.dll' because, in my situation, the project abruptly close after importing the WebRTC package without generating any crash logs in "C:\User\AppData\Local\Temp\Unity\Editor\Crashes".

Unity version: 2022.3.9f1 Package version: com.unity.webrtc@3.0.0-pre.6

karasusan commented 9 months ago

@DannisMa If you put the code which you suggested to CudaContext.cpp, is the crash stopped?

DannisMa commented 9 months ago

@DannisMa If you put the code which you suggested to CudaContext.cpp, is the crash stopped?

Yes, the crash is stopped and the project works well.

karasusan commented 9 months ago

@DannisMa I would like to aggregate the checking process in one part in code. Can you move the checking process to CudaContext.cpp ?

     static bool FindModule() 
     { 
         if (s_hModule) 
             return true; 

 #if UNITY_WIN 
         // dll delay load 
         HMODULE module = LoadLibrary(TEXT("nvcuda.dll")); 
         if (!module) 
         { 
             RTC_LOG(LS_INFO) << "nvcuda.dll is not found."; 
             return false; 
         } 
         s_hModule = module; 

>>> 
>>> // add checking process here
>>> 

 #elif UNITY_LINUX 
...
DannisMa commented 9 months ago

@karasusan Okay, I've already moved the checking process to CudaContext.cpp.