yoshinoToylogic / bulletsharp

Automatically exported from code.google.com/p/bulletsharp
MIT License
0 stars 0 forks source link

Implement PINVOKE instead of C++/CLI #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
I would like to request PINVOKE implementation of BulletSharp instead of 
C++/CLI, having it into PINVOkE would help users to have cross platform 
solution and will nicely work with OpenTK on Linux,OSX.

Thanks

Amer Koleci

Original issue reported on code.google.com by amerkol...@gmail.com on 9 Dec 2010 at 4:02

GoogleCodeExporter commented 8 years ago
Hi, Amer,

The idea is good, but it's tricky. Bullet isn't compiled into a DLL by default 
and there's no option for doing this in the CMake script. PInvoke can only link 
to DLLs (and .so files with Mono) and not obj files. So problem #1 is having to 
make a lot of changes to the build files and maintain our own version.

With GCC it's possible to take the compiled object files and link them all into 
a DLL and export all the symbols in them. Last time I tried that, it wouldn't 
export some symbols that were needed. I didn't spend much time on this, so 
maybe I did something wrong.

Another problem might be performance under Windows. C++/CLI is usually a bit 
faster than PInvoke, but I'm not sure how big the difference would be here.

A PInvoke version would definitely be useful, so I'll try doing this again some 
time. Code contributions are welcome too.

Andres

Original comment by andres.traks on 9 Dec 2010 at 11:53

GoogleCodeExporter commented 8 years ago
Is there a way to run bullet in .NET (Mono) on linux?

Original comment by hungryni...@gmail.com on 1 Jun 2011 at 3:39

GoogleCodeExporter commented 8 years ago
At the moment I'd recommend a fully managed physics engine for that such as 
http://code.google.com/p/bullet-xna/ It's XNA-centric, but I made a 
framework-agnostic branch for it too (bullet-noxna).

Original comment by andres.traks on 1 Jun 2011 at 1:40

GoogleCodeExporter commented 8 years ago
Thanks.

Where do I get bullet-noxna?

I was planning on automatically generating a p/invokes wrapper.  If that will 
work well, could you please tell me how to get bullet to compile to a dll?  I 
created an so on linux without much trouble.

Original comment by superfoo...@gmail.com on 5 Aug 2011 at 12:17

GoogleCodeExporter commented 8 years ago
I figured out how to get bullet-noxna.  Thanks

I still would like to create a bullet dll and P/Invoke it, so I can use the 
features not yet in bullet-xna.

P.S. I am also hungryninja101@gmail.com.

Original comment by superfoo...@gmail.com on 5 Aug 2011 at 12:24

GoogleCodeExporter commented 8 years ago
When I try to simply change the extension and output type, I get tons of 
unresolved external symbol errors.

Original comment by superfoo...@gmail.com on 5 Aug 2011 at 2:25

GoogleCodeExporter commented 8 years ago
The author of bullet-xna recently made his own platform-agnostic math classes 
in the 2.78 branch, so you might not need bullet-noxna anymore. The noxna 
branch still has some changes that I'd prefer to be moved to trunk though (I 
like to follow .NET standards, he likes to keep the code as similar to the 
original C++ code as possible). Anyway, I haven't tested his new code yet, so 
I'm not sure if the 2.78 branch is stable, but you could try it.

Note that bullet 3.0 is being worked on and it seems to have some sweeping 
changes, so any big advancements from me will probably related to this new 
version. See https://github.com/erwincoumans

Also, may I ask what features you're missing in bullet-xna?

Original comment by andres.traks on 5 Aug 2011 at 9:10

GoogleCodeExporter commented 8 years ago
I want soft body.  I may also later want other features; I am making a game 
engine, so I want lots of cool features.

Original comment by superfoo...@gmail.com on 5 Aug 2011 at 10:41

GoogleCodeExporter commented 8 years ago
Please tell me how to make the dll so I can use P/Invokes.

Original comment by superfoo...@gmail.com on 5 Aug 2011 at 10:45

GoogleCodeExporter commented 8 years ago
Can't remember exactly, but I think I took the obj files from the normal MinGW 
build process and tried to link them together by passing --export-all-symbols 
to the GCC linker. But as I said, I couldn't get that to work.

You need a native .dll file of Bullet to P/Invoke under Windows and a native 
.so file to P/Invoke under Linux. Renaming doesn't work.

I think the bigger problem though is that C++ is much harder to P/Invoke into 
than C.

Original comment by andres.traks on 5 Aug 2011 at 11:50

GoogleCodeExporter commented 8 years ago
Well, I got the .so, so I just need the dll, which I will auto-generate 
p/invoke code for.  In linux, I just did the standard build steps (./configure, 
make, make install), and found both .so and .a, so I'm fine with linux.

Original comment by superfoo...@gmail.com on 6 Aug 2011 at 12:32

GoogleCodeExporter commented 8 years ago
I can only build a dll for linearmath.  The others give me unresolved external 
symbol.

Original comment by superfoo...@gmail.com on 25 Aug 2011 at 3:36

GoogleCodeExporter commented 8 years ago
Consider CXXI instead of PInvoke.

Original comment by dave.hil...@gmail.com on 14 Nov 2012 at 9:18

GoogleCodeExporter commented 8 years ago
That looks useful, especially the class overriding feature. Thanks for the tip!

Original comment by andres.traks on 15 Nov 2012 at 4:44

GoogleCodeExporter commented 8 years ago
It looks like OpenSimulator have a bullet base physics plugin that uses a 
compiled dll called BulletSim and then a C# wrapper that can run in both 
Windows and Linux. Unfortunately that is not a separate project, so I am 
uncertain as to how difficult it would be to create a standalone version of 
that. Would be really interested in this as well though.

Original comment by hazard...@gmail.com on 25 Feb 2013 at 5:25

GoogleCodeExporter commented 8 years ago
Didn't know about this project, thanks!

It looks like BulletSim wraps a small subset of Bullet and adds a whole bunch 
of custom code that's not really useful outside of OpenSim.

However, there's another wrapper project that they've abandoned 2 years ago 
(looking at the log), which consists of the unmanaged libbulletnet and managed 
BulletDotNET. libbulletnet wraps Bullet's C++ classes into C methods, which 
makes PInvoking from C# easy. So that's a pretty good way to do it.

I'll create a branch of libbulletnet over here soon and start updating it.

Original comment by andres.traks on 25 Feb 2013 at 11:17

GoogleCodeExporter commented 8 years ago
Feel free to play with this alpha version:
https://code.google.com/p/bulletsharp/downloads/detail?name=bulletsharp-pinvoke-
0.1.zip

It seems to work okay, although there's still a lot of stuff missing. Also, you 
might encounter crashes on some methods, because most of the interop code is 
auto-generated and hasn't been tested.

Let me know what you think!

Original comment by andres.traks on 24 Mar 2013 at 10:56

GoogleCodeExporter commented 8 years ago
https://code.google.com/p/bulletsharp/downloads/detail?name=bulletsharp-pinvoke-
0.2.zip

Most things are now done except softbody, vehicles, multithreading and some 
other bits and pieces. I don't see any major performance issues, but more 
testing still needs to be done (for things like memory leaks, premature 
disposal, SSE alignment issues, handling null pointers, etc.).

Original comment by andres.traks on 13 Apr 2013 at 10:53

GoogleCodeExporter commented 8 years ago
Dear Andres

First of all, am very happy, couz of this project. Im a delphi developer, and i 
wish to use bullet-pinvoke for my project.
It works fine, but... couz of some memory issues after creating a world and a 
body, btDynamicsWorld_addRigidBody() crashes.
I tried to minimize any potential treath, but the problem is still present.
Maybe its delphis fault, i dont know.
i can share code or test if it helps.
Plz help me.
collerblade
collerblade@gmail.com

Original comment by collerbl...@gmail.com on 4 Jun 2013 at 8:59

GoogleCodeExporter commented 8 years ago
You are using only the libbulletc library, right? I don't expect a lot of bugs 
to be there, because it's simply a 1:1 C wrapper over C++. Although it could be 
another one of those annoying SSE alignment issues when passing btVector3 
values.

Please do share the code. Thanks!

Original comment by andres.traks on 4 Jun 2013 at 12:56

GoogleCodeExporter commented 8 years ago
Hi
Ty the quick answer.
I thought about alignment problems, but the AV is without them as well. I can 
create a demo, where am not giving any vectors to bullet, and still "ice".
But i made progress.
First of all, it can work. But it is very strange. If i compile this it works:

program Project1;
uses bullet;
var broadphase              : btBroadphaseInterface;
    collisionConfiguration  : btDefaultCollisionConfiguration;
    dispatcher              : btCollisionDispatcher;
    solver                  : btSequentialImpulseConstraintSolver;
    world                   : btDynamicsWorld;
    shape                   : btCollisionShape;
    ms                      : btMotionState;
    ci                      : btRigidBodyConstructionInfo;
    body                    : btRigidBody;
begin
broadphase:=btDbvtBroadphase_new;
collisionConfiguration:=btDefaultCollisionConfiguration_new2;
dispatcher:=btCollisionDispatcher_new(collisionConfiguration);
solver:=btSequentialImpulseConstraintSolver_new;
world:=btDiscreteDynamicsWorld_new(dispatcher,broadphase,solver,collisionConfigu
ration);
shape:=btSphereShape_new(1);
ms:=btDefaultMotionState_new;
ci:=btRigidBody_btRigidBodyConstructionInfo_new2(0,ms,shape);
body:=btRigidBody_new(ci);
btDynamicsWorld_addRigidBody(world,body);
btDynamicsWorld_removeRigidBody(world,body);
end.

this code works! But if i movethe broadphase creation into separate procedure 
its AV.

program Project1;
uses bullet;
var broadphase              : btBroadphaseInterface;
    collisionConfiguration  : btDefaultCollisionConfiguration;
    dispatcher              : btCollisionDispatcher;
    solver                  : btSequentialImpulseConstraintSolver;
    world                   : btDynamicsWorld;
    shape                   : btCollisionShape;
    ms                      : btMotionState;
    ci                      : btRigidBodyConstructionInfo;
    body                    : btRigidBody;

procedure initBullet;
begin
broadphase:=btDbvtBroadphase_new;
end;

begin
initBullet;
collisionConfiguration:=btDefaultCollisionConfiguration_new2;
dispatcher:=btCollisionDispatcher_new(collisionConfiguration);
solver:=btSequentialImpulseConstraintSolver_new;
world:=btDiscreteDynamicsWorld_new(dispatcher,broadphase,solver,collisionConfigu
ration);
shape:=btSphereShape_new(1);
ms:=btDefaultMotionState_new;
ci:=btRigidBody_btRigidBodyConstructionInfo_new2(0,ms,shape);
body:=btRigidBody_new(ci);
btDynamicsWorld_addRigidBody(world,body);
btDynamicsWorld_removeRigidBody(world,body);
end.

I suppose its somethig with pointer or memory management. But i cant figure 
out. Do i something wrong?

TY collerblade

Original comment by collerbl...@gmail.com on 5 Jun 2013 at 8:08

GoogleCodeExporter commented 8 years ago
sorry forget to mention:

1 A compiler is delphi 2007 is used for years now, and i dont think its a 
compiler error. But today i will try freepascal as well.

2 The AV is in the last line "btDynamicsWorld_removeRigidBody(world,body);" in 
the second program.

collerblade

Original comment by collerbl...@gmail.com on 5 Jun 2013 at 8:29

GoogleCodeExporter commented 8 years ago
Ok
Now is fired up freepascal and its exacly the same. I did some debugging and it 
shows that the problem is after somewhere "btAlignedVector..." so maybe u are 
correct.
Can we do something about memory allocation alignment??

ty collerblade

Original comment by collerbl...@gmail.com on 5 Jun 2013 at 9:59

GoogleCodeExporter commented 8 years ago
btDbvtBroadphase_new is the constructor that takes a parameter, try 
btDbvtBroadphase_new2 instead.

Original comment by andres.traks on 5 Jun 2013 at 2:10

GoogleCodeExporter commented 8 years ago
Wow realy. You are my saver :D. Thank You!

But let me anoher question (just a quick one):
Im using pinvoke 0.2 (Apr 2013). Witch revision is that? (currently is 516)
When are u planning to release the next version?

Ty collerblade

Original comment by collerbl...@gmail.com on 5 Jun 2013 at 6:54

GoogleCodeExporter commented 8 years ago
0.2 is the April 13th release, so it's r506.

I'll probably do a release of both BulletSharp and the PInvoke version at the 
end of June. After that I'll be away for about a year of military service.

Original comment by andres.traks on 6 Jun 2013 at 9:15

GoogleCodeExporter commented 8 years ago
ty 
sorry to hear that!

may i suggest something:
plz create "_delete" functions as well, couz of memory leaks. For example i 
cant just delete or free() memory, delphis memory management work different 
ways.

collerblade

Original comment by collerbl...@gmail.com on 7 Jun 2013 at 9:16

GoogleCodeExporter commented 8 years ago
That's a good point. The thing is, I planned to have _delete functions only for 
base classes to keep the number of exported functions low. So for example, you 
would call btCollisionObject_delete() to free a btRigidBody. I kinda expected 
that to be a bit confusing, so I'll think about adding the _delete functions 
for all classes.

Original comment by andres.traks on 8 Jun 2013 at 1:53

GoogleCodeExporter commented 8 years ago
hi
Really. In bullet destructors are virtual, so then its is enough to have 
_delete function in the base class. Thats good enough fog me. TY

Original comment by collerbl...@gmail.com on 9 Jun 2013 at 9:30

GoogleCodeExporter commented 8 years ago
Ok, cool :)

There will at least be macros like this for C:
#define btRigidBody_delete(obj) btCollisionObject_delete(obj)

and in other languages, the import name can probably be remapped if needed:
[DllImport("libbulletc", EntryPoint="btCollisionObject_delete")]
static extern IntPtr btRigidBody_delete();

because sometimes you don't want to bother looking up what the base class is.

Original comment by andres.traks on 9 Jun 2013 at 11:20

GoogleCodeExporter commented 8 years ago
hi again. Can u include the btRaycastVehicle to the 0.3 build?

Original comment by collerbl...@gmail.com on 11 Jun 2013 at 8:35

GoogleCodeExporter commented 8 years ago
Okay, I'll focus on that.

Original comment by andres.traks on 11 Jun 2013 at 8:40

GoogleCodeExporter commented 8 years ago
ty
is that possibile untill end of june?

collerblade

Original comment by collerbl...@gmail.com on 13 Jun 2013 at 7:39

GoogleCodeExporter commented 8 years ago
It's done :)

Original comment by andres.traks on 13 Jun 2013 at 1:53

GoogleCodeExporter commented 8 years ago
excelent!
Ty very much!
Can u give me a dll?

Original comment by collerbl...@gmail.com on 13 Jun 2013 at 2:00

GoogleCodeExporter commented 8 years ago
Here it is: 
https://code.google.com/p/bulletsharp/downloads/detail?name=bulletsharp-pinvoke-
0.3.zip

0.3 adds vehicles and multithreading. I think multithreading is experimental in 
bullet, so not very useful. Oh well, vehicles are good too :)

I'll do 0.4 by the end of June and add lots more demos.

Original comment by andres.traks on 14 Jun 2013 at 9:03

GoogleCodeExporter commented 8 years ago
TY it works great :P

Original comment by collerbl...@gmail.com on 17 Jun 2013 at 7:28

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Well, some stuff came up, but 0.4 is compiled now. It supports collision 
callbacks and 2D collision algorithms and has loads of bugfixes.
https://googledrive.com/host/0B2TPMwtggT0jamt6VDhXVTJwOXc/BulletSharp%20P%2FInvo
ke/bulletsharp-pinvoke-0.4.zip

I noticed that the P/Invoke version is used in CraftStudio 
(http://craftstudio.io). Besides being an awesome game-creating tool, they also 
compiled a MacOS X version of BulletSharp P/Invoke, so now we know that works. 
:)

Original comment by andres.traks on 24 Feb 2014 at 5:59

GoogleCodeExporter commented 8 years ago
Oops, that's http://craftstud.io

Original comment by andres.traks on 8 Mar 2014 at 1:04

GoogleCodeExporter commented 8 years ago
great project! 
I'm unity3d user,I hope to use pinvoke to bring its softbody in unity. pinvoke 
don't has any example in its project, some of function that i know in bullet 
are not implemented. maybe it works fine but i need a little example about 
softbody.

Original comment by arash...@gmail.com on 6 Apr 2014 at 5:52

GoogleCodeExporter commented 8 years ago
Most of the softbody code is done, some classes still need finishing up. Once 
all the demos in the main BulletSharp repository work with pinvoke, then I'll 
copy them over to the pinvoke branch.

There's still 2 months of army for me to go, so I'm not getting as much done as 
I'd like to, but I'll focus more on the softbody part in the meantime. Thanks!

Original comment by andres.traks on 6 Apr 2014 at 8:09

GoogleCodeExporter commented 8 years ago
I have tried updating my project to the PInvoke version of BulletSharp, but I 
can't reference the dll in VS2008 because it is compiled against .NET 4.0. Is 
there some way you could compile it against a lower framework version or are 
you using features of 4.0?

Original comment by hazard...@gmail.com on 12 May 2014 at 1:34

GoogleCodeExporter commented 8 years ago
You can use CMake to generate a VS2008 solution. I tried it a while ago and it 
worked, but I don't check this at every revision.

Original comment by andres.traks on 12 May 2014 at 7:34

GoogleCodeExporter commented 8 years ago
Well, I managed to compile the source from the pinvoke branch against 3.5 with 
some minor adjustments, but this is the generic bulletsharp and not then opentk 
one that I am after. I will have a look at the CMake configuration. Anyway, 
thanks for all the hard work on this library :)

Original comment by hazard...@gmail.com on 12 May 2014 at 11:22

GoogleCodeExporter commented 8 years ago
Ah, there is only a Generic pinvoke version at the moment. I'm thinking of 
adding separate assemblies like (BulletSharp.OpenTK.dll) that contain extension 
methods for graphics libraries. That way you could use both Generic vectors and 
OpenTK vectors and not have to write #ifdef hacks in the main source code.

Original comment by andres.traks on 13 May 2014 at 7:14

GoogleCodeExporter commented 8 years ago
I've been trying to get the PInvoke version of BulletSharp to run under Ubuntu 
Gnome 14.04, but so far I've had no luck. When BulletSharp tries to load 
libbulletc I get undefined symbol errors. Both the version you provide as a 
download on the project home page and svn revision 637 have this issue. If I 
run the demos under wine they work, but if I try to run them natively they 
refuse to run with the same error I get with my program: "Mono: DllImport error 
loading library 'libbulletc.so': 
'/home/ltbrandon/Development/Bullet-NET/libbulletc/bin/Release/libbulletc.so: 
undefined symbol: _ZNK16btCollisionShape17getBoundingSphereER9btVector3Rf'."

Original comment by tsgcm...@gmail.com on 26 May 2014 at 3:49

GoogleCodeExporter commented 8 years ago
0.5 is now released with many stability and performance improvements. Vehicles 
are kinda broken atm, but otherwise it's pretty much on par with the C++/CLI 
version.

There's a readme.txt that explains how to make it work under different 
platforms. So far I've tried it with Windows, Ubuntu 14.04, PC-BSD and Raspbian 
on the Raspberry PI. If you're compiling libbulletc yourself, it now uses the 
github repository of Bullet instead of the SVN one on Google Code. BulletSharp 
PInvoke and libbulletc are still hosted here for the time being.

@tsgcmail I never got that problem, so I couldn't figure out why that happens. 
I did use Ubuntu as well, but I'll test with other distros at some point.

Original comment by andres.traks on 7 Feb 2015 at 9:40

GoogleCodeExporter commented 8 years ago
Tried to use BulletSharp on a 64bit ArchLinux but it crashes an the stacktrace 
starts with:

at <unknown> <0xffffffff>
at (wrapper managed-to-native) 
BulletSharp.DefaultCollisionConfiguration.btDefaultCollisionConfiguration_new 
() <0xffffffff>

I tried v0.4 and v0.5.

Is there anything I could try to solve this?

Original comment by bradlste...@googlemail.com on 10 Feb 2015 at 6:33