Problem with auto_bind function

Hiya all,
I’m having a problem using the auto_bind function. This problem only happens if I call the function by myself, no problem when the function is called from some Panda3D methods (i.e. WindowFramework::loop_animations ).

Let me explain:
Look at the first lines of auto_bind:

void
auto_bind(PandaNode *root_node, AnimControlCollection &controls,
          int hierarchy_match_flags) {
  // First, locate all the bundles in the subgraph.
  Anims anims; 
  AnimBundles extra_anims;
  Parts parts; 
  PartBundles extra_parts;
  r_find_bundles(root_node, anims, parts);

before I enter r_find_bundles, my &parts is 0x0012fdbc and the parts variabile is kind of corrupted. When I enter r_find_bundles, &parts becomes 0x0012fdb8, and the variable is ok, so THIS is the real pointer. When r_find_bundles ends, it returns to auto_bind and &parts gets back to 0x0012fdbc (corrupted variable). This is nonsense to me, I can’t understand why.
On the other side, if auto_bind is called from a Panda3d method, like WindowFramework::loop_animations, this strange pointer behaviour doesn’t happens.

Any hint/help?

Anyway, I’m using autobind directly 'coz I want to have my own collection of AnimControl to use. The one inside WindowFramework is not accessible (private variable).

Note: I’m compiling my program with MSVC++ 2008. I tried using both a precompiled panda3d lib and a compiled-from-sources one, the problem remains.

Hi,

First, I have to ask: is your project set to “Release” mode, and did you then remove NDEBUG from the project defines? Failing to do either of these is known to cause strange behavior in a compiled C++ program.

Next, I have to ask: are you determining these pointer values by using the Watch or QuickWatch function while you step through with the Microsoft debugger? If so, take the reported values with a grain of salt: the debugger tends to get confused about local variables when stepping through a program compiled in Release mode. It doesn’t mean that the pointer is actually changing or that the map is corrupt. The only reliable way to determine pointer values is to print them out, for instance with a cerr statement.

All that being said, there should be no problems with calling auto_bind() yourself.

David

Maybe I found where the problem is…
I can fix this MSVC debugger issue using correct stack alignment.
One of the things messing with the stack at function calling is Exception handling. In order to correctly see debugging info calling auto_bind, the caller function/method HAS to be compiled with the same compiler setting auto_bind.cxx was compiled with.
I compiled my panda3d from sources with makepanda under MSVC 2008 (9.0 compiler) and the settings were:

Optimization: for speed (/O2)
C++ Exceptions: Yes with SEH exceptions (/EHa)

Compiling my calling code with these same settings seems to work for now…