using bullet physics 2.81 with my ros package (a new angle)
Hi everyone,
I posted something similar earlier but have been tracking down the weirdness and now have more insight. But I still have a question on what is going on and thus am reposting.
So the backstory:
I have been trying to get a ROS package to work with bullet 2.81. ROS has an older version of bullet in it which doesn't have everything I want. Thus the attempted upgrade. My code with bullet compiles fine and runs fine with static or shared libraries when I compile it on it's own with g++. However, when I put that same code in a ROS package and compile it with the same shared libraries from bullet, it throws a segfault every time. So I've made very very sure (ldd on the binary) that the executable is pointing to the right libraries. And in fact, I've gone in and moded the bullet source code with some print statements and when I run my code, it prints out. So I'm sure it's pointing to the right ones.
So in one sentence, my bullet code runs fine when compiled on it's own, but when compiled in a rospackage using make (instead of just using g++ at the command line) it throws a seg fault. Same code.
So the issue(s):
So after spending a bunch of time tracing down the segfault, I found that creating btRigidObject objects was sometimes returning null pointers to their motion state. Then in my code when I tried to access these null pointers, I would get a segfault. So I went and added print statements to give me the pointers in my code and in the btRigidBody.cpp file in the construtor and the function it calls (setupRigidBody). So when I create the deafultMotionState the pointer is good. When the constructor sees it, the pointer is good all the way through setupRigidBody and out again. m_optionalMotionState is also good at the end of the constructor. However, back in my code immediately after the rigid body is made, sometimes rigidBody->getMotionState() which only gives me back the private variable m_optionalMotionState is suddenly a null pointer. Even though my print statements just printed out that it wasn't right before it returned the rigidBody.
However, the behavior is also inconsistent. As in, it does not happen every time I create a rigid body with the same code (I am using a function called createRigidBody that takes some necessary arguments and does the repetitive steps and then passes me back the rigid body). For clarity, I am checking the pointer within that function immediately after the rigid body is returned by the bullet constructor so hopefully no funny business is happening in the white space.
So the times that the the motion state pointer happens to go null, a seg fault is thrown when I try to access it.
But the plot thickens. If I immediately after the rigid body is returned, I use setMotionState ...