From a68c9ca845fd29b20c86cde400e94b378b7a5702 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Thu, 18 Aug 2016 21:43:43 -0700 Subject: [PATCH] avoid MT crash in VR/physics server due to printf from separate thread. add fps display in VR use 1./240. internal substep for real-time physics sim in VR/physics server for more accurate robotics sim. --- .../ExampleBrowser/OpenGLExampleBrowser.cpp | 6 +++--- .../PhysicsServerCommandProcessor.cpp | 2 +- examples/SharedMemory/PhysicsServerExample.cpp | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp index a3238f358..be8d0f2e8 100644 --- a/examples/ExampleBrowser/OpenGLExampleBrowser.cpp +++ b/examples/ExampleBrowser/OpenGLExampleBrowser.cpp @@ -490,7 +490,7 @@ void MyComboBoxCallback(int comboId, const char* item) void MyGuiPrintf(const char* msg) { printf("b3Printf: %s\n",msg); - if (gui2) + if (!gDisableDemoSelection) { gui2->textOutput(msg); gui2->forceUpdateScrollBars(); @@ -502,7 +502,7 @@ void MyGuiPrintf(const char* msg) void MyStatusBarPrintf(const char* msg) { printf("b3Printf: %s\n", msg); - if (gui2) + if (!gDisableDemoSelection) { bool isLeft = true; gui2->setStatusBarMessage(msg,isLeft); @@ -513,7 +513,7 @@ void MyStatusBarPrintf(const char* msg) void MyStatusBarError(const char* msg) { printf("Warning: %s\n", msg); - if (gui2) + if (!gDisableDemoSelection) { bool isLeft = false; gui2->setStatusBarMessage(msg,isLeft); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index b0adbd12d..96dc083a7 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -2445,7 +2445,7 @@ void PhysicsServerCommandProcessor::stepSimulationRealTime(double dtInSec) loadUrdf("plane.urdf", btVector3(0, 0, 0), btQuaternion(0, 0, 0, 1), true, true, &bodyId, &bufferServerToClient[0], bufferServerToClient.size()); } - m_data->m_dynamicsWorld->stepSimulation(dtInSec); + m_data->m_dynamicsWorld->stepSimulation(dtInSec,10,1./240.); } } diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 59e81ac4c..489d9526f 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -872,7 +872,22 @@ void PhysicsServerExample::renderScene() static int frameCount=0; frameCount++; char bla[1024]; - sprintf(bla,"VR sub-title text test, frame %d", frameCount/2); + + static btScalar prevTime = m_clock.getTimeSeconds(); + btScalar curTime = m_clock.getTimeSeconds(); + static btScalar deltaTime = 0.f; + static int count = 10; + if (count-- < 0) + { + count = 10; + deltaTime = curTime - prevTime; + } + if (deltaTime == 0) + deltaTime = 1000; + + prevTime = curTime; + + sprintf(bla,"VR sub-title text test,fps = %f, frame %d", 1./deltaTime, frameCount/2); float pos[4]; m_guiHelper->getAppInterface()->m_renderer->getActiveCamera()->getCameraTargetPosition(pos); btTransform viewTr;