From d72cda101c9f907f3192467658008a52ee3cfdfe Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 9 Sep 2015 15:14:47 -0700 Subject: [PATCH] fixes in shared memory client/server: check for valid pointers --- .../SharedMemory/PhysicsClientExample.cpp | 39 +++++++++++++------ examples/SharedMemory/PhysicsServer.cpp | 8 ++-- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/examples/SharedMemory/PhysicsClientExample.cpp b/examples/SharedMemory/PhysicsClientExample.cpp index 7aa58f54b..e9631db16 100644 --- a/examples/SharedMemory/PhysicsClientExample.cpp +++ b/examples/SharedMemory/PhysicsClientExample.cpp @@ -203,6 +203,7 @@ void MyCallback(int buttonId, bool buttonState, void* userPtr) command.m_requestDebugLinesArguments.m_debugMode = btIDebugDraw::DBG_DrawWireframe;//:DBG_DrawConstraints; command.m_requestDebugLinesArguments.m_startingLineIndex = 0; cl->enqueueCommand(command); + break; } @@ -271,14 +272,16 @@ void PhysicsClientExample::createButtons() { bool isTrigger = false; - createButton("Load URDF",CMD_LOAD_URDF, isTrigger); - createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger); - createButton("Send Bullet Stream",CMD_SEND_BULLET_DATA_STREAM, isTrigger); - createButton("Get State",CMD_REQUEST_ACTUAL_STATE, isTrigger); - createButton("Send Desired State",CMD_SEND_DESIRED_STATE, isTrigger); - createButton("Create Box Collider",CMD_CREATE_BOX_COLLISION_SHAPE,isTrigger); - createButton("Reset Simulation",CMD_RESET_SIMULATION,isTrigger); - + if (m_guiHelper && m_guiHelper->getParameterInterface()) + { + createButton("Load URDF",CMD_LOAD_URDF, isTrigger); + createButton("Step Sim",CMD_STEP_FORWARD_SIMULATION, isTrigger); + createButton("Send Bullet Stream",CMD_SEND_BULLET_DATA_STREAM, isTrigger); + createButton("Get State",CMD_REQUEST_ACTUAL_STATE, isTrigger); + createButton("Send Desired State",CMD_SEND_DESIRED_STATE, isTrigger); + createButton("Create Box Collider",CMD_CREATE_BOX_COLLISION_SHAPE,isTrigger); + createButton("Reset Simulation",CMD_RESET_SIMULATION,isTrigger); + } } void PhysicsClientExample::initPhysics() @@ -292,7 +295,15 @@ void PhysicsClientExample::initPhysics() } else { - /* + MyCallback(CMD_LOAD_URDF, true, this); + MyCallback(CMD_STEP_FORWARD_SIMULATION,true,this); + MyCallback(CMD_STEP_FORWARD_SIMULATION,true,this); + MyCallback(CMD_RESET_SIMULATION,true,this); + // MyCallback(CMD_LOAD_URDF, true, this); + // MyCallback(CMD_STEP_FORWARD_SIMULATION,true,this); + // MyCallback(CMD_RESET_SIMULATION,true,this); + + /* m_userCommandRequests.push_back(CMD_LOAD_URDF); m_userCommandRequests.push_back(CMD_REQUEST_ACTUAL_STATE); m_userCommandRequests.push_back(CMD_SEND_DESIRED_STATE); @@ -353,7 +364,10 @@ void PhysicsClientExample::stepSimulation(float deltaTime) SliderParams slider(motorName,&motorInfo->m_velTarget); slider.m_minVal=-4; slider.m_maxVal=4; + if (m_guiHelper && m_guiHelper->getParameterInterface()) + { m_guiHelper->getParameterInterface()->registerSliderFloatParameter(slider); + } m_numMotors++; } } @@ -393,8 +407,11 @@ void PhysicsClientExample::stepSimulation(float deltaTime) //for the CMD_RESET_SIMULATION we need to do something special: clear the GUI sliders if (command.m_type==CMD_RESET_SIMULATION) { - m_guiHelper->getParameterInterface()->removeAllParameters(); - m_numMotors=0; + if (m_guiHelper->getParameterInterface()) + { + m_guiHelper->getParameterInterface()->removeAllParameters(); + } + m_numMotors=0; createButtons(); } diff --git a/examples/SharedMemory/PhysicsServer.cpp b/examples/SharedMemory/PhysicsServer.cpp index 5ced12f12..ea8cd7ed1 100644 --- a/examples/SharedMemory/PhysicsServer.cpp +++ b/examples/SharedMemory/PhysicsServer.cpp @@ -1080,9 +1080,11 @@ void PhysicsServerSharedMemory::processClientCommands() case CMD_RESET_SIMULATION: { //clean up all data - - m_data->m_guiHelper->getRenderInterface()->removeAllInstances(); - deleteDynamicsWorld(); + if (m_data && m_data->m_guiHelper && m_data->m_guiHelper->getRenderInterface()) + { + m_data->m_guiHelper->getRenderInterface()->removeAllInstances(); + } + deleteDynamicsWorld(); createEmptyDynamicsWorld(); SharedMemoryStatus& serverCmd =m_data->createServerStatus(CMD_CLIENT_COMMAND_COMPLETED,clientCmd.m_sequenceNumber,timeStamp);