[Solved]Segfault after adding variable to a class of PandaAi

Hi community!. I’m working with the PandaAi library, trying to implement some changes. The problem that i am facing is a segmentation fault, after adding just a variable of type double in the class AiCharacter, an initializing it in the constructor with an arbitrary number. The name of the variable is _elapTime. The code looks like this:
in aiCharacter.h:

class AICharacter {
  double _elapTime;

and in aiCharacter.cxx:

AICharacter::AICharacter(string model_name, NodePath model_np, double mass, double movt_force, double max_force) {
	_elapTime = 0.0;

I was having also a segmentation fault working with variables allocated in the heap, using the malloc system call, but after reading this: panda3d.org/dox/python/html/ … l#_details

i started to fallback to the beginning of the development, and observed that the problem is still present under the simple declaration-initialization of that variable of type double. To compile the library i’m using all the steps of the compilation process of the entire Panda3D game engine: i extracted the flags of the call to interrogate, interrogate_module and g++ (to compile and link). I tried the process of compilation of the library without modifications, and it works fine. All the nightmare starts after adding my numeric variable. I am working under Ubuntu 11.10 64 bits. Does anybody have any idea about why i’m having such a segfault?, must i try first to learn how to debug with gdb that piece of code in c++ in order to obtain a trace of the segfault that will certainly make clear the error?. I have no idea of how to debug in this situation (my game is in python, and i need to debug a c++ library of Panda). I searched in the forum about that topic first, but i find some difficulties in order to understand the process of debugging in this setting. But, more important, there is no such a big piece of code to debug!. Thanks in advance!

Since adding a new member to a class normally wouldn’t cause a crash, I strongly suspect you’re getting a cross-contamination from some other build of Panda in which this change doesn’t exist. That would cause a crash such as you describe.

Make sure you aren’t inadvertently picking up an .so from a standard build of Panda. To be completely sure, maybe you should completely uninstall any builds of Panda except for the one you’ve made with this change.


Thanks for the reply!. Seems like you were right!. As i was making an experiment with the pandaai library, i was working on a very messy environment, working directly on the directory that contains that pandaai library, in the panda3d source code. Also i made a script to reproduce all the interrogate-interrogate_module-g++ process, that makes reference (in the calling to interrogate and g++) to some directories of the panda3d. In particular, there was a reference to the directory built/include that also has the headers of the pandaai library (the directory with the original source code of the library pandaai is contrib/src/ai). So i had differents versions of the same headers in the directory built/include and in the directory contrib/src/ai. Making sure that the versions of the headers are the same, seems to be enough to solve the problem. Next step: clean up this mess. Thanks very much for your help!