bullet hello world sample error

hi all
i got a big problem with bullet hello world sample cxx one
that when i try to run the program i got this error:
assertion failed:previous->getShapeType() == EMPTY_SHAPE_PROXYTYPE in line 186
c:\panda3d\panda3d\panda\src\bulletbodynode.cxx
by the way i build this sample with msvc 2010 and so the panda engine
so please any thing could help and thanks all

Hmm… didn’t know we have C++ samples. In my opinion developers who use C++ are better off using Bullet directly, than letting them restrict by the Panda3D/Bullet module - it is primarily intended for Python.

Anyway, can you show me the code which is before the “add_shape” call?
The assertion means that our internal bookeeping thinks that there is no BulletShape added to the RigidBody when you call “add_shape”, but somehow the (Bullet) root shape is no longer in it’s initial state (which is a special “empty” shape provided by Bullet).

I would also need to know which version of Panda3D you are using.

Hi again and sorry for late
I am using panda3d version 1.8.1 which i build it my self with msvc 2010 and here is the code i used to create the
plane shape

BulletPlaneShape *floor_shape = new BulletPlaneShape(LVecBase3f(0, 0, 1), 1);
BulletRigidBodyNode *floor_rigid_node = new BulletRigidBodyNode("Ground");
 
floor_rigid_node->add_shape(floor_shape);
 
NodePath np_ground = window->get_render().attach_new_node(floor_rigid_node);
np_ground.set_pos(0, 0, -2);
physics_world->attach_rigid_body(floor_rigid_node);

I think I found your problem.

Objects like BulletWorld, BulletShape or BulletRigidBodyNode are derived fromTypedReferenceCount. Actually, many Panda3D objects are. You have to use smart pointers to store them, i. e. “PT(PandaNode)” instead of “PandaNode *”. Once the last reference (PT(…)) is out of scope they get destroyed. So in your case you create a new BulletShape via “new”, but don’t store it in a smart pointer. This means it immediately gets destroyed again.

This is how you should do it:

  NodePath floor_np;
  {
    PT(BulletPlaneShape) floor_shape = new BulletPlaneShape(LVecBase3f(0, 0, 1), 0);
    PT(BulletRigidBodyNode) floor_node = new BulletRigidBodyNode("Ground");
 
    floor_node->add_shape(floor_shape);
    floor_np = window->get_render().attach_new_node(floor_node);
    floor_np.set_pos(0, 0, 0);

    world->attach_rigid_body(floor_node);
  }

I don’t like the example given in the tutorial, since it does not use smart pointers correctly. I tried to optimize it a little bit:

#include "pandaFramework.h"
#include "windowFramework.h"
#include "nodePath.h"
#include "clockObject.h"
 
#include "asyncTask.h"
#include "genericAsyncTask.h"
 
#include "bulletWorld.h"
#include "bulletPlaneShape.h"
#include "bulletBoxShape.h"

PT(BulletWorld) get_world() {
  static PT(BulletWorld) physics_world = new BulletWorld();
  return physics_world;
}

AsyncTask::DoneStatus update_scene(GenericAsyncTask* task, void* data) {
  ClockObject *co = ClockObject::get_global_clock();
  get_world()->do_physics(co->get_dt(), 10, 1.0 / 180.0);
  return AsyncTask::DS_cont;
}
 
int main(int argc, char *argv[]) {
 
  // Framework
  PandaFramework framework;
  framework.open_framework(argc, argv);
  framework.set_window_title("Bullet Physics");
 
  WindowFramework *window = framework.open_window();
  window->enable_keyboard();
  window->setup_trackball();
 
  // World
  PT(BulletWorld) world = get_world();
  world->set_gravity(0, 0, -9.8);

  // Debug
  NodePath debug_np;
  {
    PT(BulletDebugNode) debug_node = new BulletDebugNode("Debug");

    debug_node->show_bounding_boxes(false);
    debug_node->show_constraints(true);
    debug_node->show_normals(false);
    debug_node->show_wireframe(true);
    debug_np = window->get_render().attach_new_node(debug_node);
    debug_np.show();
 
    world->set_debug_node(debug_node);
  }

  // Floor
  NodePath floor_np;
  {
    PT(BulletPlaneShape) floor_shape = new BulletPlaneShape(LVecBase3f(0, 0, 1), 0);
    PT(BulletRigidBodyNode) floor_node = new BulletRigidBodyNode("Ground");
 
    floor_node->add_shape(floor_shape);
    floor_np = window->get_render().attach_new_node(floor_node);
    floor_np.set_pos(0, 0, 0);

    world->attach_rigid_body(floor_node);
  }

  // Box
  NodePath box_np;
  {
    PT(BulletBoxShape) box_shape = new BulletBoxShape(LVecBase3f(0.5, 0.5, 0.5));
    PT(BulletRigidBodyNode) box_node = new BulletRigidBodyNode("Box");
 
    box_node->set_mass(1.0);
    box_node->add_shape(box_shape);
    box_np = window->get_render().attach_new_node(box_node);
    box_np.set_pos(0, 0, 6);

    world->attach_rigid_body(box_node);

    //NodePath model_np = window->load_model(framework.get_models(), "models/box");
    //model_np.reparent_to(box_np);
  }

  // Task
  PT(GenericAsyncTask) task;
  task = new GenericAsyncTask("update", &update_scene, (void*) NULL);
  AsyncTaskManager::get_global_ptr()->add(task);
 
  // Loop
  framework.main_loop();
  framework.close_framework();
 
  return (0);
}

Hi enn0x i got to thank you for the sample that you offered ,but it just help me to jump over the problem for a while,i mean there is no more assertion failed except when i run the program as an administrator .
and even if i tried to run it normally it just draw black window and then its crash,
so i started think that its build problem with msvc 2010

This is strange. Might be wrong compiler/linker flags, but this is just guessing. Can you provide the sample solution as a zip-file for download? And i which lines does the crash occur?

Here is the sln file which contain the bullet sample
and here is my build output:

1>------ Rebuild All started: Project: bullet, Configuration: Release Win32 ------
1>Build started 31/07/2013 02:44:03 م.
1>_PrepareForClean:
1>  Deleting file "Release\bullet.lastbuildstate".
1>InitializeBuildStatus:
1>  Creating "Release\bullet.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  main.cpp
1>c:\panda3d-1.8.1\include\bulletClosestHitRayResult.h(31): warning C4275: non dll-interface struct 'btCollisionWorld::ClosestRayResultCallback' used as base for dll-interface struct 'BulletClosestHitRayResult'
1>          C:\panda3d\panda3d\thirdparty\win-libs-vc9\bullet\include\BulletCollision/CollisionDispatch/btCollisionWorld.h(233) : see declaration of 'btCollisionWorld::ClosestRayResultCallback'
1>          c:\panda3d-1.8.1\include\bulletClosestHitRayResult.h(31) : see declaration of 'BulletClosestHitRayResult'
1>c:\panda3d-1.8.1\include\bulletAllHitsRayResult.h(54): warning C4275: non dll-interface struct 'btCollisionWorld::AllHitsRayResultCallback' used as base for dll-interface struct 'BulletAllHitsRayResult'
1>          C:\panda3d\panda3d\thirdparty\win-libs-vc9\bullet\include\BulletCollision/CollisionDispatch/btCollisionWorld.h(267) : see declaration of 'btCollisionWorld::AllHitsRayResultCallback'
1>          c:\panda3d-1.8.1\include\bulletAllHitsRayResult.h(54) : see declaration of 'BulletAllHitsRayResult'
1>c:\panda3d-1.8.1\include\bulletClosestHitSweepResult.h(31): warning C4275: non dll-interface struct 'btCollisionWorld::ClosestConvexResultCallback' used as base for dll-interface struct 'BulletClosestHitSweepResult'
1>          C:\panda3d\panda3d\thirdparty\win-libs-vc9\bullet\include\BulletCollision/CollisionDispatch/btCollisionWorld.h(365) : see declaration of 'btCollisionWorld::ClosestConvexResultCallback'
1>          c:\panda3d-1.8.1\include\bulletClosestHitSweepResult.h(31) : see declaration of 'BulletClosestHitSweepResult'
1>c:\panda3d-1.8.1\include\bulletContactResult.h(56): warning C4275: non dll-interface struct 'btCollisionWorld::ContactResultCallback' used as base for dll-interface struct 'BulletContactResult'
1>          C:\panda3d\panda3d\thirdparty\win-libs-vc9\bullet\include\BulletCollision/CollisionDispatch/btCollisionWorld.h(403) : see declaration of 'btCollisionWorld::ContactResultCallback'
1>          c:\panda3d-1.8.1\include\bulletContactResult.h(56) : see declaration of 'BulletContactResult'
1>Link:
1>  Generating code
1>  Finished generating code
1>  bullet.vcxproj -> D:\Myprojects\bullet\Release\bullet.exe
1>FinalizeBuildStatus:
1>  Deleting file "Release\bullet.unsuccessfulbuild".
1>  Touching "Release\bullet.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:27.12
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

bullet_test.zip (3.96 KB)

Hmmm, seems like something with the project settings is wrong, but I’m not really an expert with VS settings. When building with WAF (my prefered build system) I get a working executable.

Can you try to build with waf too? I have attached a minimal project. You don’t need anything else than the content of the zip-file. Just edit the file “wscript” and adjust the two paths in line 28 and 29, then type “waf configure” and then “waf build”.
waf_test.zip (89.2 KB)

Hi enn0x and thank you for solving this problem to me ,now the sample is working properly.