Lock the sim mutex in PhysicsLoop and PhysicsThread.
This prevents an invalid memory access when the stack is used in engine_vis. Fixes #1219. PiperOrigin-RevId: 588017796 Change-Id: I1ee18c5aa5e96ccaeebb0a467cd384355882b80b
This commit is contained in:
committed by
Copybara-Service
parent
c062a8db19
commit
8c7c39a211
+16
-1
@@ -267,6 +267,9 @@ void PhysicsLoop(mj::Simulate& sim) {
|
||||
if (dnew) {
|
||||
sim.Load(mnew, dnew, sim.dropfilename);
|
||||
|
||||
// lock the sim mutex
|
||||
const std::unique_lock<std::recursive_mutex> lock(sim.mtx);
|
||||
|
||||
mj_deleteData(d);
|
||||
mj_deleteModel(m);
|
||||
|
||||
@@ -292,6 +295,9 @@ void PhysicsLoop(mj::Simulate& sim) {
|
||||
if (dnew) {
|
||||
sim.Load(mnew, dnew, sim.filename);
|
||||
|
||||
// lock the sim mutex
|
||||
const std::unique_lock<std::recursive_mutex> lock(sim.mtx);
|
||||
|
||||
mj_deleteData(d);
|
||||
mj_deleteModel(m);
|
||||
|
||||
@@ -421,9 +427,18 @@ void PhysicsThread(mj::Simulate* sim, const char* filename) {
|
||||
if (filename != nullptr) {
|
||||
sim->LoadMessage(filename);
|
||||
m = LoadModel(filename, *sim);
|
||||
if (m) d = mj_makeData(m);
|
||||
if (m) {
|
||||
// lock the sim mutex
|
||||
const std::unique_lock<std::recursive_mutex> lock(sim->mtx);
|
||||
|
||||
d = mj_makeData(m);
|
||||
}
|
||||
if (d) {
|
||||
sim->Load(m, d, filename);
|
||||
|
||||
// lock the sim mutex
|
||||
const std::unique_lock<std::recursive_mutex> lock(sim->mtx);
|
||||
|
||||
mj_forward(m, d);
|
||||
|
||||
// allocate ctrlnoise
|
||||
|
||||
Reference in New Issue
Block a user