Skip to content

Commit

Permalink
* Fix #263: unload native lib before updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mnboos committed Oct 26, 2019
1 parent bc3c750 commit f69a06e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ about=Plugin which reads vector tiles according to Mapbox' Vector Tiles specific
* Nextzen.org
* OpenInfraMap.org
This Python plugin uses prebuilt C++ binaries for performance reasons.
version=3.2.1
version=3.2.2
author=Martin Boos
[email protected]

Expand All @@ -23,6 +23,8 @@ [email protected]

# Uncomment the following line and add your changelog:
changelog=
---3.2.2---
* Fix: Make sure native library is unloaded before trying to update it
---3.2.1---
* Fix: Loading error on Mac
* Fix: Loading of native decoding library
Expand Down
16 changes: 10 additions & 6 deletions plugin/util/mp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def _get_lib_path():
if not os.path.isdir(temp_dir):
os.makedirs(temp_dir)
if os.path.isfile(temp_lib_path) and os.path.getmtime(temp_lib_path) != os.path.getmtime(lib_path):
info("Updating native lib...")
unload_lib()
os.remove(temp_lib_path)
if not os.path.isfile(temp_lib_path):
shutil.copy2(lib_path, temp_dir)
Expand All @@ -62,11 +64,13 @@ def _get_lib_path():

def load_lib():
global _native_lib_handle

path = _get_lib_path()

if _native_lib_handle:
info("The native dll is already loaded, not loading again...")
info("The native lib is already loaded, not loading again...")
else:
info("Loading native dll...")
path = _get_lib_path()
info("Loading native lib...")
if path and os.path.isfile(path):
try:
lib = cdll.LoadLibrary(path)
Expand Down Expand Up @@ -97,7 +101,7 @@ def unload_lib():
global _native_lib_handle
system = platform.system()
try:
info("Unloading native dll...")
info("Unloading native lib...")
if _native_lib_handle:
if system == "Windows":
from ctypes import windll
Expand All @@ -106,9 +110,9 @@ def unload_lib():
else:
_native_lib_handle.dlclose()
else:
info("Dll already unloaded")
info("Native lib already unloaded")
except Exception:
critical("Unloading native dll failed on {}: {}", system, sys.exc_info())
critical("Unloading native lib failed on {}: {}", system, sys.exc_info())
finally:
_native_lib_handle = None

Expand Down

0 comments on commit f69a06e

Please sign in to comment.