|
16 | 16 | import os |
17 | 17 | import sys |
18 | 18 |
|
| 19 | +# Keep DLL directory handles alive to prevent garbage collection (Windows only) |
| 20 | +_dll_directory_handles = [] |
| 21 | + |
19 | 22 | if sys.platform == 'linux' or sys.platform == 'linux2': |
20 | 23 | path = os.path.join('lib', 'controller', 'libController.so') |
21 | 24 | elif sys.platform == 'win32': |
22 | 25 | path = os.path.join('lib', 'controller', 'Controller.dll') |
| 26 | + # Since Python 3.8, dependent DLLs are no longer found via PATH on Windows. |
| 27 | + # Add directories containing required runtime DLLs to the search path. |
| 28 | + webots_home = os.environ['WEBOTS_HOME'] |
| 29 | + for dll_dir in [ |
| 30 | + os.path.join(webots_home, 'lib', 'controller'), |
| 31 | + # In the installed distribution, MinGW runtime DLLs (libgcc_s_seh-1.dll, |
| 32 | + # libwinpthread-1.dll, libstdc++-6.dll) are placed in msys64/mingw64/bin/cpp. |
| 33 | + os.path.join(webots_home, 'msys64', 'mingw64', 'bin', 'cpp'), |
| 34 | + os.path.join(webots_home, 'msys64', 'mingw64', 'bin'), |
| 35 | + ]: |
| 36 | + if os.path.isdir(dll_dir): |
| 37 | + _dll_directory_handles.append(os.add_dll_directory(dll_dir)) |
| 38 | + # For development builds running from source, also check the system MSYS2 installation. |
| 39 | + mingw_bin = os.path.join(os.environ.get('MSYS2_HOME', |
| 40 | + os.path.splitdrive(sys.executable)[0] + os.sep + 'msys64'), |
| 41 | + 'mingw64', |
| 42 | + 'bin') |
| 43 | + if os.path.isdir(mingw_bin): |
| 44 | + _dll_directory_handles.append(os.add_dll_directory(mingw_bin)) |
23 | 45 | elif sys.platform == 'darwin': |
24 | 46 | path = os.path.join('Contents', 'lib', 'controller', 'libController.dylib') |
25 | 47 |
|
|
0 commit comments