asynchronous shape creation [SOLVED - PATCH included]

gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

asynchronous shape creation [SOLVED - PATCH included]

Post by gjaegy »

Hi,

I am currently switching the shapes creation phase from the main thread to a job-bases (multi-threaded) asynchronous loading system.

Therefore, I would like some inputs about the thread-safety of some of Bullet internal functions.

I guess this shouldn't be a problem, but could someone confirm the following functions are fully encapsulated and are thread safe ?

Code: Select all

BulletCreateConvexHullShape()
ConvexBuilder::process()
BulletCreateTriangleIndexVertexArray()
BulletCreateBvhTriangleMeshShape()
I suppose this shouldn't be a problem, but a confirmation of that would be really welcome ;)

FYI, the bodies are added to the world in the main thread (all world related functions are called in the main thread).

Thanks,

Greg
Last edited by gjaegy on Mon Mar 28, 2011 1:03 pm, edited 1 time in total.
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

hmmm, I actually get a crash in cd_hull.cpp, line 2526 (latest SVN rev):

Code: Select all

float3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]);
I am now going to investigate what can be causing this issue (likely a concurrency issue, as I didn't have the crash prior to implementing the asynchronous object creation).

As this kind of bugs is quite hard to fix (as it doesn't happen with a debugger attached), if anyone has some inputs, please feel free to share them ;)
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

global variable :(

Code: Select all

Array<btHullTriangle*> tris;
it seems quite easy to fix this...

Erwin, shall I do it (will do anyway actually) and provide you with a diff ?
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

attached:

- the patch (diff file)
- html view of the changes (winmerge-like view)

I would appreciate if it could be merged into the main trunk...

Thanks in advance.
You do not have the required permissions to view the files attached to this post.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: asynchronous shape creation

Post by Flix »

Interesting and useful fix, thanks for posting :wink:

As far as I remember cd_hull.cpp is part of the ConvexDecomposition library shipped with Bullet, isn't it?
That is an external library, so I don't know if your changes could be merged (of course I'm not a Bullet developer... just guessing).

PS. There's another (SVN) version of that library here (http://codesuppository.blogspot.com/200 ... y-now.html) that is slightly different from the one Bullet includes (basically one more parameter can be tweaked and there's an option to create the shapes in another thread, but to me the new version seems a bit slower and more difficult to "tune" to get an uniform behavior for all the concave shapes passed to it; even if with fine tuning better results can be achieved). Probably you already know it, since there's a Bullet issue talking about it (http://code.google.com/p/bullet/issues/detail?id=401).
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

I wasn't aware of this being an external library, thanks for the information ;)

Let's see what Erwin will decide (hopefully he will read this thread !)
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

hmmm, actually it seems there are some other changes to perform, as the creation still crash on another test system.
from a quick look, some other static variables in "class VertexLess".
will fix right now.
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

dear, getting rid of VertexLess class two static members is not that easy...
anybody could help on that please ?
[EDIT: forget my request, i got it, testing right now]
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation

Post by gjaegy »

I think I managed to encapsulate all the classes, to allow several multithreaded convex decomposition processes to run simultaneously.

Attached the .diff file showing the changes for the "Extras\ConvexDecomposition" folder.

Also, some HTML winmerge report showing the changes visually.

Feel free to use (or add to SVN main trunk :))
You do not have the required permissions to view the files attached to this post.
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: asynchronous shape creation [SOLVED-PATCH included]

Post by gjaegy »

[UP]
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: asynchronous shape creation [SOLVED - PATCH included]

Post by Erwin Coumans »

Thanks for the patch, we'll have a look at it.

We recently added the new LinearMath/btConvexHullComputer.cpp, which should be faster and more robust than cd_hull (Stan Hull).

It would be worthwhile trying to replace it for the convex decomposition code.
THanks,
Erwin