From 28b86ba0a4bf7cf68f51889b2a74ba0463b57da4 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 16 May 2018 08:32:21 -0700 Subject: [PATCH 1/4] fix some tsan issues (thread sanitizer) --- examples/MultiThreading/b3PosixThreadSupport.cpp | 3 ++- examples/SharedMemory/PhysicsServerExample.cpp | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/MultiThreading/b3PosixThreadSupport.cpp b/examples/MultiThreading/b3PosixThreadSupport.cpp index dfec90df6..cd5117182 100644 --- a/examples/MultiThreading/b3PosixThreadSupport.cpp +++ b/examples/MultiThreading/b3PosixThreadSupport.cpp @@ -268,7 +268,8 @@ void b3PosixThreadSupport::stopThreads() for(size_t t=0; t < size_t(m_activeThreadStatus.size()); ++t) { b3ThreadStatus& spuStatus = m_activeThreadStatus[t]; - printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), spuStatus.threadUsed); + + // printf("%s: Thread %i used: %ld\n", __FUNCTION__, int(t), spuStatus.threadUsed); spuStatus.m_userPtr = 0; checkPThreadFunction(sem_post(spuStatus.startSemaphore)); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 03a085a34..f4bfbe967 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -260,6 +260,8 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) if (init) { + unsigned int cachedSharedParam = eMotionIsInitialized; + args->m_cs->lock(); args->m_cs->setSharedParam(0,eMotionIsInitialized); args->m_cs->unlock(); @@ -269,6 +271,8 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) int numCmdSinceSleep1ms = 0; unsigned long long int prevTime = clock.getTimeMicroseconds(); + + do { { @@ -468,7 +472,11 @@ void MotionThreadFunc(void* userPtr,void* lsMemory) numCmdSinceSleep1ms++; } - } while (args->m_cs->getSharedParam(0)!=eRequestTerminateMotion); + args->m_cs->lock(); + cachedSharedParam = args->m_cs->getSharedParam(0); + args->m_cs->unlock(); + + } while (cachedSharedParam!=eRequestTerminateMotion); } else { args->m_cs->lock(); @@ -1749,7 +1757,7 @@ void PhysicsServerExample::initPhysics() m_isConnected = m_physicsServer.connectSharedMemory( m_guiHelper); - + for (int i=0;igetNumTasks();i++) { From 0ca2c5f925448a86269235206785ae47e2002759 Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Wed, 16 May 2018 12:10:34 -0700 Subject: [PATCH 2/4] use Bullet3Common/b3AlignedObjectArray.h instead of LinearMath version in SharedMemory/PhysicsClientSharedMemory --- .../PhysicsClientSharedMemory.cpp | 46 +++++++++---------- examples/SharedMemory/Win32SharedMemory.cpp | 4 +- src/Bullet3Common/b3AlignedObjectArray.h | 8 ++++ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/examples/SharedMemory/PhysicsClientSharedMemory.cpp b/examples/SharedMemory/PhysicsClientSharedMemory.cpp index a9bf810e6..c78eff91c 100644 --- a/examples/SharedMemory/PhysicsClientSharedMemory.cpp +++ b/examples/SharedMemory/PhysicsClientSharedMemory.cpp @@ -1,10 +1,10 @@ #include "PhysicsClientSharedMemory.h" #include "PosixSharedMemory.h" #include "Win32SharedMemory.h" -#include "LinearMath/btAlignedObjectArray.h" -#include "LinearMath/btVector3.h" +#include "Bullet3Common/b3AlignedObjectArray.h" +#include "Bullet3Common/b3Vector3.h" #include - +#include "Bullet3Common/b3HashMap.h" #include "Bullet3Common/b3Logging.h" #include "../Utils/b3ResourcePath.h" #include "../../Extras/Serialize/BulletFileLoader/btBulletFile.h" @@ -19,7 +19,7 @@ struct BodyJointInfoCache { std::string m_baseName; - btAlignedObjectArray m_jointInfo; + b3AlignedObjectArray m_jointInfo; std::string m_bodyName; }; @@ -28,32 +28,32 @@ struct PhysicsClientSharedMemoryInternalData { bool m_ownsSharedMemory; SharedMemoryBlock* m_testBlock1; - btHashMap m_bodyJointMap; - btHashMap m_userConstraintInfoMap; + b3HashMap m_bodyJointMap; + b3HashMap m_userConstraintInfoMap; - btAlignedObjectArray m_debugLinesFrom; - btAlignedObjectArray m_debugLinesTo; - btAlignedObjectArray m_debugLinesColor; + b3AlignedObjectArray m_debugLinesFrom; + b3AlignedObjectArray m_debugLinesTo; + b3AlignedObjectArray m_debugLinesColor; int m_cachedCameraPixelsWidth; int m_cachedCameraPixelsHeight; - btAlignedObjectArray m_cachedCameraPixelsRGBA; - btAlignedObjectArray m_cachedCameraDepthBuffer; - btAlignedObjectArray m_cachedSegmentationMaskBuffer; + b3AlignedObjectArray m_cachedCameraPixelsRGBA; + b3AlignedObjectArray m_cachedCameraDepthBuffer; + b3AlignedObjectArray m_cachedSegmentationMaskBuffer; - btAlignedObjectArray m_cachedContactPoints; - btAlignedObjectArray m_cachedOverlappingObjects; - btAlignedObjectArray m_cachedVisualShapes; - btAlignedObjectArray m_cachedCollisionShapes; + b3AlignedObjectArray m_cachedContactPoints; + b3AlignedObjectArray m_cachedOverlappingObjects; + b3AlignedObjectArray m_cachedVisualShapes; + b3AlignedObjectArray m_cachedCollisionShapes; - btAlignedObjectArray m_cachedVREvents; - btAlignedObjectArray m_cachedKeyboardEvents; - btAlignedObjectArray m_cachedMouseEvents; - btAlignedObjectArray m_cachedMassMatrix; - btAlignedObjectArray m_raycastHits; + b3AlignedObjectArray m_cachedVREvents; + b3AlignedObjectArray m_cachedKeyboardEvents; + b3AlignedObjectArray m_cachedMouseEvents; + b3AlignedObjectArray m_cachedMassMatrix; + b3AlignedObjectArray m_raycastHits; - btAlignedObjectArray m_bodyIdsRequestInfo; - btAlignedObjectArray m_constraintIdsRequestInfo; + b3AlignedObjectArray m_bodyIdsRequestInfo; + b3AlignedObjectArray m_constraintIdsRequestInfo; SharedMemoryStatus m_tempBackupServerStatus; diff --git a/examples/SharedMemory/Win32SharedMemory.cpp b/examples/SharedMemory/Win32SharedMemory.cpp index 7a2c688ea..4c7e04d6c 100644 --- a/examples/SharedMemory/Win32SharedMemory.cpp +++ b/examples/SharedMemory/Win32SharedMemory.cpp @@ -2,7 +2,7 @@ #include "Win32SharedMemory.h" #include "Bullet3Common/b3Logging.h" #include "Bullet3Common/b3Scalar.h" -#include "LinearMath/btAlignedObjectArray.h" +#include "Bullet3Common/b3AlignedObjectArray.h" #include #include @@ -29,7 +29,7 @@ struct Win32SharedMemorySegment struct Win32SharedMemoryInteralData { - btAlignedObjectArray m_segments; + b3AlignedObjectArray m_segments; Win32SharedMemoryInteralData() { diff --git a/src/Bullet3Common/b3AlignedObjectArray.h b/src/Bullet3Common/b3AlignedObjectArray.h index 947362d08..ef7101656 100644 --- a/src/Bullet3Common/b3AlignedObjectArray.h +++ b/src/Bullet3Common/b3AlignedObjectArray.h @@ -528,6 +528,14 @@ protected: otherArray.copy(0, otherSize, m_data); } + void removeAtIndex(int index) + { + if (index Date: Wed, 16 May 2018 14:24:12 -0700 Subject: [PATCH 3/4] fix VR controllers only visible in one eye (remove stray glClear for testing planar reflection) PyBullet: force both contactStiffness and contactDamping (report error otherwise) --- examples/OpenGLWindow/GLInstancingRenderer.cpp | 2 +- examples/OpenGLWindow/Win32OpenGLWindow.cpp | 6 +++--- examples/pybullet/pybullet.c | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index 26d765536..1a66c32df 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -1618,7 +1618,7 @@ void GLInstancingRenderer::renderScene() { renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE); - glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + if (m_planeReflectionShapeIndex>=0) { diff --git a/examples/OpenGLWindow/Win32OpenGLWindow.cpp b/examples/OpenGLWindow/Win32OpenGLWindow.cpp index 28eab35cb..aa71750ad 100644 --- a/examples/OpenGLWindow/Win32OpenGLWindow.cpp +++ b/examples/OpenGLWindow/Win32OpenGLWindow.cpp @@ -119,9 +119,9 @@ void Win32OpenGLWindow::closeWindow() void Win32OpenGLWindow::startRendering() { pumpMessage(); - //don't clear all 3 buffers because some AMD drivers are buggy - //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); + //glCullFace(GL_BACK); diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 4e0785021..1fae95a6d 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -937,6 +937,12 @@ static PyObject* pybullet_changeDynamicsInfo(PyObject* self, PyObject* args, PyO return NULL; } + if ((contactStiffness>=0 && contactDamping <0)||(contactStiffness<0 && contactDamping >=0)) + { + PyErr_SetString(SpamError, "Both contactStiffness and contactDamping needs to be set together."); + return NULL; + } + { b3SharedMemoryCommandHandle command = b3InitChangeDynamicsInfo(sm); b3SharedMemoryStatusHandle statusHandle; From ff646fbef28d1c9ef58d795c9b0f5036780d56e6 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 17 May 2018 12:18:17 -0700 Subject: [PATCH 4/4] workaround for an out-of-date tinyxml2 version --- .../ImportMJCFDemo/BulletMJCFImporter.cpp | 8 ++++++++ .../Importers/ImportURDFDemo/UrdfParser.cpp | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp index 95e1d4a34..97696a839 100644 --- a/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp +++ b/examples/Importers/ImportMJCFDemo/BulletMJCFImporter.cpp @@ -241,7 +241,11 @@ struct BulletMJCFImporterInternalData return buf; #else char row[1024]; +#ifdef G3_TINYXML2 + sprintf(row,"unknown line, upgrade tinyxml2 version!"); +#else sprintf(row,"%d",e->GetLineNum()); +#endif std::string str = m_sourceFileName.c_str() + std::string(":") + std::string(row); return str; #endif @@ -1491,8 +1495,12 @@ bool BulletMJCFImporter::parseMJCFString(const char* xmlText, MJCFErrorLogger* l xml_doc.Parse(xmlText); if (xml_doc.Error()) { +#ifdef G3_TINYXML2 + logger->reportError("xml reading error (upgrade tinyxml2 version!"); +#else logger->reportError(xml_doc.ErrorStr()); xml_doc.ClearError(); +#endif return false; } diff --git a/examples/Importers/ImportURDFDemo/UrdfParser.cpp b/examples/Importers/ImportURDFDemo/UrdfParser.cpp index 1be8285c1..b39eff2d8 100644 --- a/examples/Importers/ImportURDFDemo/UrdfParser.cpp +++ b/examples/Importers/ImportURDFDemo/UrdfParser.cpp @@ -1,5 +1,4 @@ #include "UrdfParser.h" - #include "../../ThirdPartyLibs/tinyxml2/tinyxml2.h" #include "urdfStringSplit.h" #include "urdfLexicalCast.h" @@ -1504,8 +1503,12 @@ bool UrdfParser::loadUrdf(const char* urdfText, ErrorLogger* logger, bool forceF xml_doc.Parse(urdfText); if (xml_doc.Error()) { +#ifdef G3_TINYXML2 + logger->reportError("xml reading error"); +#else logger->reportError(xml_doc.ErrorStr()); xml_doc.ClearError(); +#endif return false; } @@ -1664,9 +1667,13 @@ bool UrdfParser::loadSDF(const char* sdfText, ErrorLogger* logger) xml_doc.Parse(sdfText); if (xml_doc.Error()) { +#ifdef G3_TINYXML2 + logger->reportError("xml reading error"); +#else logger->reportError(xml_doc.ErrorStr()); xml_doc.ClearError(); - return false; +#endif + return false; } XMLElement *sdf_xml = xml_doc.FirstChildElement("sdf"); @@ -1847,8 +1854,12 @@ std::string UrdfParser::sourceFileLocation(XMLElement* e) return buf; #else char row[1024]; +#ifdef G3_TINYXML2 + sprintf(row,"unknown line"); +#else sprintf(row,"%d",e->GetLineNum()); - std::string str = m_urdf2Model.m_sourceFile.c_str() + std::string(":") + std::string(row); +#endif + std::string str = m_urdf2Model.m_sourceFile.c_str() + std::string(":") + std::string(row); return str; #endif