From 9ba7c439b45a454f7c5178668aa1494268ff142f Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 18 Jul 2017 11:54:27 +0200 Subject: [PATCH] Add flag for local or global opening of main lib --- source/carla_backend.py | 4 ++-- source/carla_backend_qt.py | 4 ++-- source/carla_host.py | 23 ++++++++++++++++++----- source/carla_shared.py | 2 ++ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/source/carla_backend.py b/source/carla_backend.py index ecfff28be..5f9ba6749 100644 --- a/source/carla_backend.py +++ b/source/carla_backend.py @@ -2100,13 +2100,13 @@ class CarlaHostNull(CarlaHostMeta): # Carla Host object using a DLL class CarlaHostDLL(CarlaHostMeta): - def __init__(self, libName): + def __init__(self, libName, localLoad): CarlaHostMeta.__init__(self) # info about this host object self.isPlugin = False - self.lib = CDLL(libName, RTLD_GLOBAL) + self.lib = CDLL(libName, RTLD_LOCAL if localLoad else RTLD_GLOBAL) self.lib.carla_get_engine_driver_count.argtypes = None self.lib.carla_get_engine_driver_count.restype = c_uint diff --git a/source/carla_backend_qt.py b/source/carla_backend_qt.py index 7a6097330..eff13d480 100644 --- a/source/carla_backend_qt.py +++ b/source/carla_backend_qt.py @@ -91,9 +91,9 @@ class CarlaHostQtNull(CarlaHostNull, CarlaHostSignals): # Carla Host object using a DLL class CarlaHostQtDLL(CarlaHostDLL, CarlaHostSignals): - def __init__(self, libName): + def __init__(self, libName, localLoad): CarlaHostSignals.__init__(self) - CarlaHostDLL.__init__(self, libName) + CarlaHostDLL.__init__(self, libName, localLoad) # ------------------------------------------------------------------------------------------------------------ # Carla Host object for plugins (using pipes) diff --git a/source/carla_host.py b/source/carla_host.py index d6f9cbf6a..f00fc8f4a 100644 --- a/source/carla_host.py +++ b/source/carla_host.py @@ -2325,6 +2325,16 @@ def fileCallback(ptr, action, isDir, title, filter): def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = None): pathBinaries, pathResources = getPaths(libPrefix) + # -------------------------------------------------------------------------------------------------------- + # Check if we should open main lib as local or global + + settings = QSettings("falkTX", "Carla2") + + try: + loadLocal = settings.value(CARLA_KEY_MAIN_LOAD_LIB_LOCAL, CARLA_DEFAULT_MAIN_LOAD_LIB_LOCAL, type=bool) + except: + loadLocal = CARLA_DEFAULT_MAIN_LOAD_LIB_LOCAL + # -------------------------------------------------------------------------------------------------------- # Fail if binary dir is not found @@ -2337,8 +2347,9 @@ def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = No # -------------------------------------------------------------------------------------------------------- # Set Carla library name - libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION) - utilsname = "libcarla_utils.%s" % (DLL_EXTENSION) + libname = "libcarla_%s2.%s" % ("control" if isControl else "standalone", DLL_EXTENSION) + libname = os.path.join(pathBinaries, libname) + utilsname = os.path.join(pathBinaries, "libcarla_utils.%s" % (DLL_EXTENSION)) # -------------------------------------------------------------------------------------------------------- # Print info @@ -2353,12 +2364,14 @@ def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = No # -------------------------------------------------------------------------------------------------------- # Init host + + if failError: # no try - host = HostClass() if HostClass is not None else CarlaHostQtDLL(os.path.join(pathBinaries, libname)) + host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadLocal) else: try: - host = HostClass() if HostClass is not None else CarlaHostQtDLL(os.path.join(pathBinaries, libname)) + host = HostClass() if HostClass is not None else CarlaHostQtDLL(libname, loadLocal) except: host = CarlaHostQtNull() @@ -2381,7 +2394,7 @@ def initHost(initName, libPrefix, isControl, isPlugin, failError, HostClass = No # -------------------------------------------------------------------------------------------------------- # Init utils - gCarla.utils = CarlaUtils(os.path.join(pathBinaries, utilsname)) + gCarla.utils = CarlaUtils(utilsname) gCarla.utils.set_process_name(os.path.basename(initName)) try: diff --git a/source/carla_shared.py b/source/carla_shared.py index 676259e68..384d800da 100644 --- a/source/carla_shared.py +++ b/source/carla_shared.py @@ -194,6 +194,7 @@ CARLA_KEY_MAIN_REFRESH_INTERVAL = "Main/RefreshInterval" # int CARLA_KEY_MAIN_USE_CUSTOM_SKINS = "Main/UseCustomSkins" # bool CARLA_KEY_MAIN_MANAGE_UIS = "Main/ManageUIs" # bool CARLA_KEY_MAIN_SHOW_LOGS = "Main/ShowLogs" # bool +CARLA_KEY_MAIN_LOAD_LIB_LOCAL = "Main/LoadLibsLocal" # bool CARLA_KEY_CANVAS_THEME = "Canvas/Theme" # str CARLA_KEY_CANVAS_SIZE = "Canvas/Size" # str "NxN" @@ -239,6 +240,7 @@ CARLA_DEFAULT_MAIN_REFRESH_INTERVAL = 20 CARLA_DEFAULT_MAIN_USE_CUSTOM_SKINS = True CARLA_DEFAULT_MAIN_MANAGE_UIS = True CARLA_DEFAULT_MAIN_SHOW_LOGS = bool(not WINDOWS) +CARLA_DEFAULT_MAIN_LOAD_LIB_LOCAL = True # Canvas CARLA_DEFAULT_CANVAS_THEME = "Modern Dark"