Is rayTest thread safe?

Post Reply
monty_hall
Posts: 4
Joined: Tue Feb 23, 2016 10:59 pm

Is rayTest thread safe?

Post by monty_hall »

The signature is const, so I would think that it is thread safe.

Code: Select all

virtual void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;
Please advise, because I 'm getting strange behavior when I run it multithreaded. In a static scene, multiple rayTests for the same ray doesn't return the same result; it manifests itself as a "sparkle" when I draw the intersection points. Running single threaded this doesn't happen.

Thanks,

M
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Is rayTest thread safe?

Post by Flix »

Is rayTest thread safe?
I've never tried, but, according to: http://bulletphysics.org/Bullet/phpBB3/ ... &hilit=ray, to make it thread safe some changes must be applied.
Probably these changes (but I don't know if these are the ONLY changes required):
https://github.com/lunkhound/bullet3/co ... 84b7d1926d
anthrax11
Posts: 72
Joined: Wed Feb 24, 2010 9:49 pm

Re: Is rayTest thread safe?

Post by anthrax11 »

The const keyword means that the rayTest method doesn't modify the world object.
Other non-const methods such as stepSimulation can still change the object in another thread while rayTest is running.
svedach
Posts: 12
Joined: Mon Sep 01, 2014 6:53 am

Re: Is rayTest thread safe?

Post by svedach »

I think we should try to do as it is written in https://github.com/lunkhound/bullet3/co ... 6fafdaL266. I will try to do it tomorrow and put the results here.
svedach
Posts: 12
Joined: Mon Sep 01, 2014 6:53 am

Re: Is rayTest thread safe?

Post by svedach »

I could not get. I did as it is written at the link above, but when I call rayTest from multiple threads, the heap error occurs. It's a pity.
Xammond
Posts: 15
Joined: Sun Jan 03, 2016 4:22 pm

Re: Is rayTest thread safe?

Post by Xammond »

Might not be what you're looking for, but as the scene is static then you could have a duplicate dynamics world running on a seperate thread with a raytest queue. I found that this previously produced results quickly enough for my needs (camera, particles).
svedach
Posts: 12
Joined: Mon Sep 01, 2014 6:53 am

Re: Is rayTest thread safe?

Post by svedach »

I think in many cases create a copy of the world after the simulation will be slow operation. We need to make to the existing world raytest multithreaded.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Is rayTest thread safe?

Post by Basroil »

svedach wrote:I could not get. I did as it is written at the link above, but when I call rayTest from multiple threads, the heap error occurs. It's a pity.
Are you sure that your threads are off while stepping the world and only polling the system between steps?
svedach
Posts: 12
Joined: Mon Sep 01, 2014 6:53 am

Re: Is rayTest thread safe?

Post by svedach »

Fully convinced that stop simulation when the RayTest.
Xammond
Posts: 15
Joined: Sun Jan 03, 2016 4:22 pm

Re: Is rayTest thread safe?

Post by Xammond »

svedach wrote:I think in many cases create a copy of the world after the simulation will be slow operation. We need to make to the existing world raytest multithreaded.
Yes it would be. My suggestion was to do so just once at runtime, but that is game specific based on a static world (not dynamic actors).
Post Reply