Multithread crashes

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Multithread crashes

Postby KingSnail » Sun Mar 13, 2011 1:54 pm

Hi I have a problem with newton running on a different thread

So my setup is like this

Main thread: Server loop + CreatePlayerController() when players join

Second Thread: Loop with NewtonUpdate()
this is done with createthreadex and not newton dThread class

8 other threads: These are Newton worker threads that are built in to Newton
I just specified 8 to Newton.

The problem is this, When the player controller gets made it creates a body first and then a player controller which creates 3 more bodies (The sensors)
As soon as first body is created I get a crash from one of the 8 Newton threads about trying to access a sensor shape which hasnt been made yet
because it gets constructed in CustomPlayerController base class.

So my question is: Is it possible to let create a new Newton body that doesnt instantly add it to the NewtonUpdate loop?
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Multithread crashes

Postby Julio Jerez » Sun Mar 13, 2011 2:09 pm

are you using newton 3.0?

are you creating the objet in a newton callback?
if you are you can create you body inside a newton critical section
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multithread crashes

Postby KingSnail » Sun Mar 13, 2011 4:53 pm

I am using Newton 2.0

I am not creating the controller inside a call back.

I have tried using critical sections outside of callback but they end up making the thread (main thread)
that is not a newton thread go into sleep().

Is it possible to make newton create a body without adding it to the main list of bodies?

/**********************/

create_newton_body(); <----- adds body to NewtonUpdate it seems here
charactercontroller(body);
sensor1();
sensor2(); <----- Cannot read 0x0c0c... Crash here on an update thread
sensor3();
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Multithread crashes

Postby Julio Jerez » Sun Mar 13, 2011 5:51 pm

Use the newton Critical section. That should work.

and No in 2.00 you cannot create a body without adding it to the world.

can you create after the Newton update? That spud be very safe and clean.
I never tried to make joints in a call back. so I do not know how it will work, and now I am in the middle of a bs, windows installation
upgrading me window system to the new Intel Core two, so I can not check it out.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multithread crashes

Postby KingSnail » Sun Mar 13, 2011 6:08 pm

I cant call it after NewtonUpdate because NewtonUpdate is running async to the main thread
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Multithread crashes

Postby Julio Jerez » Sun Mar 13, 2011 8:01 pm

sure you can, if you are making it in a newton call back, you can also do it after the newton update.
The callback are all made in the before Newton Update exits, so there will be not disycronizatiion.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multithread crashes

Postby KingSnail » Tue Mar 15, 2011 2:22 pm

How can I make a body in a callback?
I mean why would I want to do that?

A new player connects then I want to make a body

How would I integrate this in a callback?

Sorry confused
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Multithread crashes

Postby Julio Jerez » Tue Mar 15, 2011 3:32 pm

I say do not do it in the call back save the information, an ddo it after NewtonUpdate returns.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Multithread crashes

Postby ledahut » Wed Mar 16, 2011 3:29 pm

I am not sure but maybe freeze update while creating you player should work (use a global boolean flag for example, or just stop thread, or just use some thread priority).
But I think what you want is priority to newton update thread, so my method won't work for you.
ledahut
 
Posts: 98
Joined: Mon Jun 21, 2010 8:03 am
Location: France

Re: Multithread crashes

Postby almaris » Wed Mar 16, 2011 3:48 pm

I ran into this issue myself, the fix was in the customplayercontroller ctor moving this line:
==
NewtonUserJointSetFeedbackCollectorCallback (m_joint, KinematicMotion);
==
to after the sensor shape creation
almaris
 
Posts: 6
Joined: Tue Jan 25, 2011 1:12 pm

Re: Multithread crashes

Postby KingSnail » Sat Mar 19, 2011 10:52 am

Thanks, that is a another solution to the fix, I fixed it this way also:

Code: Select all
auto temp_body = CreatePlayerBody(ZoneCollisionPtr->World, avatar_->Mass, location, size, avatar_->MaterialID, avatar_);
   std::shared_ptr<CustomPlayerController>cpc(new MyPlayerController(globalFrame, maxStairStepFactor, kinematicCushion, temp_body)); //Cant do make_shared because new operator overload in newton joint class
   auto castt = std::dynamic_pointer_cast<MyPlayerController>(cpc);
   castt->BODY = temp_body;
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests