From 2d65738a186e7ebc4ec4a8cb56d43891fcaedcd6 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Dec 2020 14:10:51 +0100 Subject: [PATCH 1/8] makepanda: Respect lib-10.6 dir when copying dylibs/running install_name_tool In the 1.10.8 thirdparty packages, OpenCV is split into a lib folder and a lib-10.6 folder, so we should use the proper dylibs to still be able to target 10.6 --- makepanda/makepanda.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 609218002c..eadb8ce189 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -3265,13 +3265,18 @@ if tp_dir is not None: if GetTarget() == 'darwin': # Make a list of all the dylibs we ship, to figure out whether we should use # install_name_tool to correct the library reference to point to our copy. - for lib in glob.glob(tp_dir + "/*/lib/*.dylib"): - dylibs[os.path.basename(lib)] = os.path.basename(os.path.realpath(lib)) + for pkg in PkgListGet(): + if PkgSkip(pkg): + continue - if not PkgSkip("PYTHON"): - for lib in glob.glob(tp_dir + "/*/lib/" + SDK["PYTHONVERSION"] + "/*.dylib"): + tp_libdir = GetThirdpartyLibDir(pkg) + for lib in glob.glob(os.path.join(tp_libdir, "*.dylib")): dylibs[os.path.basename(lib)] = os.path.basename(os.path.realpath(lib)) + if not PkgSkip("PYTHON"): + for lib in glob.glob(os.path.join(tp_libdir, SDK["PYTHONVERSION"], "*.dylib")): + dylibs[os.path.basename(lib)] = os.path.basename(os.path.realpath(lib)) + for pkg in PkgListGet(): if PkgSkip(pkg): continue @@ -3284,13 +3289,14 @@ if tp_dir is not None: CopyAllFiles(GetOutputDir() + "/bin/", tp_pkg + "/bin/" + SDK["PYTHONVERSION"] + "/") elif GetTarget() == 'darwin': - tp_libs = glob.glob(tp_pkg + "/lib/*.dylib") + tp_libdir = GetThirdpartyLibDir(pkg) + tp_libs = glob.glob(os.path.join(tp_libdir, "*.dylib")) if not PkgSkip("PYTHON"): - tp_libs += glob.glob(os.path.join(tp_pkg, "lib", SDK["PYTHONVERSION"], "*.dylib")) - tp_libs += glob.glob(os.path.join(tp_pkg, "lib", SDK["PYTHONVERSION"], "*.so")) + tp_libs += glob.glob(os.path.join(tp_libdir, SDK["PYTHONVERSION"], "*.dylib")) + tp_libs += glob.glob(os.path.join(tp_libdir, SDK["PYTHONVERSION"], "*.so")) if pkg != 'PYTHON': - tp_libs += glob.glob(os.path.join(tp_pkg, "lib", SDK["PYTHONVERSION"], "*.py")) + tp_libs += glob.glob(os.path.join(tp_libdir, SDK["PYTHONVERSION"], "*.py")) for tp_lib in tp_libs: basename = os.path.basename(tp_lib) From 8ba1ae924cf6fcc44cf320b02edc3aee688d32b2 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Dec 2020 15:26:15 +0100 Subject: [PATCH 2/8] tkwidgets: Fix EntryScale missing import and menu errors --- direct/src/tkwidgets/EntryScale.py | 52 +++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/direct/src/tkwidgets/EntryScale.py b/direct/src/tkwidgets/EntryScale.py index c9685fcf6c..bf72d61855 100644 --- a/direct/src/tkwidgets/EntryScale.py +++ b/direct/src/tkwidgets/EntryScale.py @@ -5,6 +5,7 @@ EntryScale Class: Scale with a label, and a linked and validated entry __all__ = ['EntryScale', 'EntryScaleGroup'] from direct.showbase.TkGlobal import * +from panda3d.core import Vec4 import Pmw, sys if sys.version_info >= (3, 0): @@ -482,17 +483,24 @@ def rgbPanel(nodePath, callback = None): esg.component('menubar').component('EntryScale Group-button')['text'] = ( 'RGBA Panel') # Update menu - menu = esg.component('menubar').component('EntryScale Group-menu') + menubar = esg.component('menubar') + menubar.deletemenuitems('EntryScale Group', 1, 1) + # Some helper functions # Clear color - menu.insert_command(index = 1, label = 'Clear Color', - command = lambda np = nodePath: np.clearColor()) - # Set Clear Transparency - menu.insert_command(index = 2, label = 'Set Transparency', - command = lambda np = nodePath: np.setTransparency(1)) - menu.insert_command( - index = 3, label = 'Clear Transparency', - command = lambda np = nodePath: np.clearTransparency()) + menubar.addmenuitem( + 'EntryScale Group', 'command', + label='Clear Color', command=lambda np=nodePath: np.clearColor()) + + # Set/Clear Transparency + menubar.addmenuitem( + 'EntryScale Group', 'command', + label='Set Transparency', command=lambda np=nodePath: np.setTransparency(1)) + menubar.addmenuitem( + 'EntryScale Group', 'command', + label='Clear Transparency', + command=lambda np=nodePath: np.clearTransparency()) + # System color picker def popupColorPicker(esg = esg): # Can pass in current color with: color = (255, 0, 0) @@ -502,13 +510,27 @@ def rgbPanel(nodePath, callback = None): initialcolor = tuple(esg.get()[:3]))[0] if color: esg.set((color[0], color[1], color[2], esg.getAt(3))) - menu.insert_command(index = 4, label = 'Popup Color Picker', - command = popupColorPicker) + + menubar.addmenuitem( + 'EntryScale Group', 'command', + label='Popup Color Picker', command=popupColorPicker) + def printToLog(nodePath=nodePath): - c=nodePath.getColor() - print("Vec4(%.3f, %.3f, %.3f, %.3f)"%(c[0], c[1], c[2], c[3])) - menu.insert_command(index = 5, label = 'Print to log', - command = printToLog) + c = nodePath.getColor() + print("Vec4(%.3f, %.3f, %.3f, %.3f)" % (c[0], c[1], c[2], c[3])) + + menubar.addmenuitem( + 'EntryScale Group', 'command', + label='Print to log', command=printToLog) + + # Add back the Dismiss item we removed. + if esg['fDestroy']: + dismissCommand = esg.destroy + else: + dismissCommand = esg.withdraw + menubar.addmenuitem( + 'EntryScale Group', 'command', 'Dismiss EntryScale Group panel', + label='Dismiss', command=dismissCommand) # Set callback def onRelease(r, g, b, a, nodePath = nodePath): From 7c676b5d26621c8aa20e45f65efd6e104090ef68 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Dec 2020 15:26:32 +0100 Subject: [PATCH 3/8] directtools: Fix incorrect rounding for color conversion to hex The color picker returns color values up to 255.99 so this can otherwise result in it returning a color like #100100100, and the hex code otherwise not matching with what is displayed in the color picker. --- direct/src/directtools/DirectUtil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/direct/src/directtools/DirectUtil.py b/direct/src/directtools/DirectUtil.py index 2a244e325c..43d46831cb 100644 --- a/direct/src/directtools/DirectUtil.py +++ b/direct/src/directtools/DirectUtil.py @@ -19,7 +19,7 @@ def getTkColorString(color): Print out a Tk compatible version of a color string """ def toHex(intVal): - val = int(round(intVal)) + val = int(intVal) if val < 16: return "0" + hex(val)[2:] else: From 6b1c681a244a02ccd510dec56afe783c3c667e0b Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Dec 2020 15:50:43 +0100 Subject: [PATCH 4/8] extensions_native: Fix indirect rgbPanel import It's defined in Valuator, not in Slider --- direct/src/extensions_native/NodePath_extensions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/direct/src/extensions_native/NodePath_extensions.py b/direct/src/extensions_native/NodePath_extensions.py index 4c388becf7..6756819f47 100644 --- a/direct/src/extensions_native/NodePath_extensions.py +++ b/direct/src/extensions_native/NodePath_extensions.py @@ -432,8 +432,8 @@ def rgbPanel(self, cb = None): # Don't use a regular import, to prevent ModuleFinder from picking # it up as a dependency when building a .p3d package. import importlib - Slider = importlib.import_module('direct.tkwidgets.Slider') - return Slider.rgbPanel(self, cb) + Valuator = importlib.import_module('direct.tkwidgets.Valuator') + return Valuator.rgbPanel(self, cb) Dtool_funcToMethod(rgbPanel, NodePath) del rgbPanel From b5c857c73f40b66fafe4c2c655d84cf12769b5c0 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Dec 2020 23:50:07 +0100 Subject: [PATCH 5/8] pgraphnodes: Backport ShaderGenerator stub to 1.10.x Needed if interrogate is being run with the __aarch64__ definition in a multi-arch build --- panda/src/pgraphnodes/shaderGenerator.cxx | 24 +++++++++++++++++++++++ panda/src/pgraphnodes/shaderGenerator.h | 16 ++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/panda/src/pgraphnodes/shaderGenerator.cxx b/panda/src/pgraphnodes/shaderGenerator.cxx index 6c9b9b8a03..bfb466409e 100644 --- a/panda/src/pgraphnodes/shaderGenerator.cxx +++ b/panda/src/pgraphnodes/shaderGenerator.cxx @@ -2028,4 +2028,28 @@ operator == (const ShaderKey &other) const { && _light_ramp == other._light_ramp; } +#else + +// Stubs for when building without Cg support. +ShaderGenerator:: +ShaderGenerator(const GraphicsStateGuardianBase *gsg) { +} + +ShaderGenerator:: +~ShaderGenerator() { +} + +void ShaderGenerator:: +rehash_generated_shaders() { +} + +void ShaderGenerator:: +clear_generated_shaders() { +} + +CPT(ShaderAttrib) ShaderGenerator:: +synthesize_shader(const RenderState *rs, const GeomVertexAnimationSpec &anim) { + return nullptr; +} + #endif // HAVE_CG diff --git a/panda/src/pgraphnodes/shaderGenerator.h b/panda/src/pgraphnodes/shaderGenerator.h index a3d37c4ad9..7ef11d148d 100644 --- a/panda/src/pgraphnodes/shaderGenerator.h +++ b/panda/src/pgraphnodes/shaderGenerator.h @@ -18,14 +18,14 @@ #include "pandabase.h" #include "typedReferenceCount.h" +#include "graphicsStateGuardianBase.h" +#include "shaderAttrib.h" +#include "renderState.h" #ifdef HAVE_CG -#include "graphicsStateGuardianBase.h" #include "graphicsOutputBase.h" #include "nodePath.h" -#include "shaderAttrib.h" -#include "renderState.h" #include "renderAttrib.h" #include "colorAttrib.h" @@ -196,6 +196,16 @@ private: // If we don't have Cg, let's replace this with a stub. class EXPCL_PANDA_PGRAPHNODES ShaderGenerator : public TypedReferenceCount { +PUBLISHED: + ShaderGenerator(const GraphicsStateGuardianBase *gsg); + virtual ~ShaderGenerator(); + + virtual CPT(ShaderAttrib) synthesize_shader(const RenderState *rs, + const GeomVertexAnimationSpec &anim); + + void rehash_generated_shaders(); + void clear_generated_shaders(); + public: static TypeHandle get_class_type() { return _type_handle; From 74983d19a41d5fbf006cb269d6b1adc9f705dc99 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 20 Dec 2020 00:19:37 +0100 Subject: [PATCH 6/8] dtoolbase: Fix small memory leak in NeverFreeMemory It's using a set purely keyed by number of remaining bytes, so if there are two pages with the exact same number of remaining bytes, one of them gets lost. See #1077 --- dtool/src/dtoolbase/neverFreeMemory.I | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dtool/src/dtoolbase/neverFreeMemory.I b/dtool/src/dtoolbase/neverFreeMemory.I index 6e5216e993..bc608040e3 100644 --- a/dtool/src/dtoolbase/neverFreeMemory.I +++ b/dtool/src/dtoolbase/neverFreeMemory.I @@ -80,7 +80,11 @@ Page(void *start, size_t size) : */ INLINE bool NeverFreeMemory::Page:: operator < (const NeverFreeMemory::Page &other) const { - return _remaining < other._remaining; + if (_remaining != other._remaining) { + return _remaining < other._remaining; + } else { + return _next < other._next; + } } /** From f7ab42da56041fa458b8a2e27baaadd44863aeb2 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 20 Dec 2020 00:23:04 +0100 Subject: [PATCH 7/8] putil: Fix memory leak in SimpleHashMap Fixes #1077 --- panda/src/putil/simpleHashMap.I | 53 ++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/panda/src/putil/simpleHashMap.I b/panda/src/putil/simpleHashMap.I index 2ac26a54f0..545e0aa49c 100644 --- a/panda/src/putil/simpleHashMap.I +++ b/panda/src/putil/simpleHashMap.I @@ -37,17 +37,19 @@ SimpleHashMap(const SimpleHashMap ©) : // We allocate enough bytes for _table_size elements of TableEntry, plus // _table_size * 4 more ints at the end (for the index array). - size_t alloc_size = _table_size * (sizeof(TableEntry) + sizeof(int) * sparsity); + if (_table_size > 0) { + size_t alloc_size = _table_size * (sizeof(TableEntry) + sizeof(int) * sparsity); - _deleted_chain = memory_hook->get_deleted_chain(alloc_size); - _table = (TableEntry *)_deleted_chain->allocate(alloc_size, TypeHandle::none()); + _deleted_chain = memory_hook->get_deleted_chain(alloc_size); + _table = (TableEntry *)_deleted_chain->allocate(alloc_size, TypeHandle::none()); - for (size_t i = 0; i < _num_entries; ++i) { - new(&_table[i]) TableEntry(copy._table[i]); + for (size_t i = 0; i < _num_entries; ++i) { + new(&_table[i]) TableEntry(copy._table[i]); + } + + // Copy the index array. + memcpy(get_index_array(), copy.get_index_array(), _table_size * sizeof(int) * sparsity); } - - // Copy the index array. - memcpy(get_index_array(), copy.get_index_array(), _table_size * sizeof(int) * sparsity); } /** @@ -84,22 +86,39 @@ template INLINE SimpleHashMap &SimpleHashMap:: operator = (const SimpleHashMap ©) { if (this != ©) { + TableEntry *old_table = _table; + DeletedBufferChain *old_deleted_chain = _deleted_chain; + size_t old_num_entries = _num_entries; + _table_size = copy._table_size; _num_entries = copy._num_entries; _comp = copy._comp; - // We allocate enough bytes for _table_size elements of TableEntry, plus - // _table_size * 4 more ints at the end (for the index array). - size_t alloc_size = _table_size * (sizeof(TableEntry) + sizeof(int) * sparsity); + if (_table_size > 0) { + // We allocate enough bytes for _table_size elements of TableEntry, plus + // _table_size * 4 more ints at the end (for the index array). + size_t alloc_size = _table_size * (sizeof(TableEntry) + sizeof(int) * sparsity); - _deleted_chain = memory_hook->get_deleted_chain(alloc_size); - _table = (TableEntry *)_deleted_chain->allocate(alloc_size, TypeHandle::none()); - for (size_t i = 0; i < _num_entries; ++i) { - new(&_table[i]) TableEntry(copy._table[i]); + _deleted_chain = memory_hook->get_deleted_chain(alloc_size); + _table = (TableEntry *)_deleted_chain->allocate(alloc_size, TypeHandle::none()); + for (size_t i = 0; i < _num_entries; ++i) { + new(&_table[i]) TableEntry(copy._table[i]); + } + + // Copy the index array. + memcpy(get_index_array(), copy.get_index_array(), _table_size * sizeof(int) * sparsity); + } else { + _table = nullptr; + _deleted_chain = nullptr; } - // Copy the index array. - memcpy(get_index_array(), copy.get_index_array(), _table_size * sizeof(int) * sparsity); + if (old_table != nullptr) { + for (size_t i = 0; i < old_num_entries; ++i) { + old_table[i].~TableEntry(); + } + + old_deleted_chain->deallocate(old_table, TypeHandle::none()); + } } return *this; } From ac021e94d6a8ec4acfd9e95945b82a86f895b54e Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 20 Dec 2020 00:57:20 +0100 Subject: [PATCH 8/8] putil: Ensure SimpleHashMap::_deleted_chain/_table are always initialized Good to be on the safe side. --- panda/src/putil/simpleHashMap.I | 2 ++ 1 file changed, 2 insertions(+) diff --git a/panda/src/putil/simpleHashMap.I b/panda/src/putil/simpleHashMap.I index 545e0aa49c..62809b4ffe 100644 --- a/panda/src/putil/simpleHashMap.I +++ b/panda/src/putil/simpleHashMap.I @@ -31,6 +31,8 @@ SimpleHashMap(const Compare &comp) : template INLINE SimpleHashMap:: SimpleHashMap(const SimpleHashMap ©) : + _table(nullptr), + _deleted_chain(nullptr), _table_size(copy._table_size), _num_entries(copy._num_entries), _comp(copy._comp) {