Skip to content

Commit

Permalink
fix an error when releasing DLL resources on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed Oct 22, 2023
1 parent 9b6d23f commit 89cbb05
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
38 changes: 24 additions & 14 deletions addons/blender_dds_addon/directx/texconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,34 @@
DLL = None


def get_dll_close_from_lib(lib_name):
"""Return dll function to unlaod DLL if the library has it."""
dlpath = find_library(lib_name)
if dlpath is None:
# DLL not found.
return None
try:
lib = ctypes.CDLL(dlpath)
if hasattr(lib, "dlclose"):
return lib.dlclose
except OSError:
pass
# dlclose not found.
return None


def get_dll_close():
"""Get dll function to unload DLL."""
if util.is_windows():
return ctypes.windll.kernel32.FreeLibrary
else:
dlpath = find_library("c")
if dlpath is None:
dlpath = find_library("System")
elif dlpath is None:
# Failed to find the path to stdlib.
return None

try:
stdlib = ctypes.CDLL(dlpath)
return stdlib.dlclose
except OSError:
# Failed to load stdlib.
return None
# Search libc, libdl, and libSystem
for lib_name in ["c", "dl", "System"]:
dlclose = get_dll_close_from_lib(lib_name)
if dlclose is not None:
return dlclose
# Failed to find dlclose
return None


def unload_texconv():
Expand All @@ -43,7 +53,7 @@ def unload_texconv():

dll_close = get_dll_close()
if dll_close is None:
raise RuntimeError("Failed to unload DLL. Restart Blender if you will remove the addon.")
raise RuntimeError("Failed to unload DLL.")

handle = DLL._handle
dll_close.argtypes = [ctypes.c_void_p]
Expand Down
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ver 0.3.3
- Fixed a bug that sRGB formats make textures brighter when exporting.
- Fixed an error when importing files from some specific directory structures.
- Fixed a bug that the `Import from a Directory` operation can not count DDS files correctly.
- Fixed an error when releasing DLL resources on Linux.
- Made the addon release DLL resources for each operation.
- Added an error for ARM devices.

Expand Down

0 comments on commit 89cbb05

Please sign in to comment.