Modify signature of plugin reset callback.
The `reset` function is called inside `mj_resetData`, before any physics forwarding call has been made. It is therefore an error to read anything from mjData at this stage. The only valid operation on mjData during `reset` is for a plugin to write into its own state variable slots and data struct. We modify the function signature to only provide access to these. PiperOrigin-RevId: 495032492 Change-Id: Ic6d2967d2571a9083cbca1ba239ca70a8a51f474
This commit is contained in:
committed by
Copybara-Service
parent
2e6af64b31
commit
5c021d042b
@@ -1179,7 +1179,7 @@ struct mjpPlugin_ {
|
|||||||
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
||||||
|
|
||||||
// called when an mjData is being reset (required)
|
// called when an mjData is being reset (required)
|
||||||
void (*reset)(const mjModel* m, mjData* d, int instance);
|
void (*reset)(const mjModel* m, double* plugin_state, void* plugin_data, int instance);
|
||||||
|
|
||||||
// called when the plugin needs to update its outputs (required)
|
// called when the plugin needs to update its outputs (required)
|
||||||
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ struct mjpPlugin_ {
|
|||||||
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
void (*copy)(mjData* dest, const mjModel* m, const mjData* src, int instance);
|
||||||
|
|
||||||
// called when an mjData is being reset (required)
|
// called when an mjData is being reset (required)
|
||||||
void (*reset)(const mjModel* m, mjData* d, int instance);
|
void (*reset)(const mjModel* m, double* plugin_state, void* plugin_data, int instance);
|
||||||
|
|
||||||
// called when the plugin needs to update its outputs (required)
|
// called when the plugin needs to update its outputs (required)
|
||||||
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
void (*compute)(const mjModel* m, mjData* d, int instance, int capability_bit);
|
||||||
|
|||||||
@@ -1149,7 +1149,8 @@ static void _resetData(const mjModel* m, mjData* d, unsigned char debug_value) {
|
|||||||
d->plugin[i] = m->plugin[i];
|
d->plugin[i] = m->plugin[i];
|
||||||
const mjpPlugin* plugin = mjp_getPluginAtSlot(m->plugin[i]);
|
const mjpPlugin* plugin = mjp_getPluginAtSlot(m->plugin[i]);
|
||||||
if (plugin->reset) {
|
if (plugin->reset) {
|
||||||
plugin->reset(m, d, i);
|
plugin->reset(m, &d->plugin_state[m->plugin_stateadr[i]],
|
||||||
|
(void*)(d->plugin_data[i]), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -224,8 +224,9 @@ int RegisterSensorPlugin() {
|
|||||||
TestSensor::DestroyCount()++;
|
TestSensor::DestroyCount()++;
|
||||||
};
|
};
|
||||||
|
|
||||||
plugin.reset = +[](const mjModel* m, mjData* d, int instance) {
|
plugin.reset = +[](const mjModel* m, double* plugin_state, void* plugin_data,
|
||||||
auto sensor = reinterpret_cast<TestSensor*>(d->plugin_data[instance]);
|
int instance) {
|
||||||
|
auto sensor = reinterpret_cast<TestSensor*>(plugin_data);
|
||||||
sensor->Reset();
|
sensor->Reset();
|
||||||
};
|
};
|
||||||
plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) {
|
plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) {
|
||||||
@@ -266,8 +267,9 @@ int RegisterActuatorPlugin() {
|
|||||||
TestActuator::DestroyCount()++;
|
TestActuator::DestroyCount()++;
|
||||||
};
|
};
|
||||||
|
|
||||||
plugin.reset = +[](const mjModel* m, mjData* d, int instance) {
|
plugin.reset = +[](const mjModel* m, double* plugin_state, void* plugin_data,
|
||||||
auto actuator = reinterpret_cast<TestActuator*>(d->plugin_data[instance]);
|
int instance) {
|
||||||
|
auto actuator = reinterpret_cast<TestActuator*>(plugin_data);
|
||||||
actuator->Reset();
|
actuator->Reset();
|
||||||
};
|
};
|
||||||
plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) {
|
plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) {
|
||||||
@@ -306,8 +308,9 @@ int RegisterPassivePlugin() {
|
|||||||
d->plugin_data[instance] = 0;
|
d->plugin_data[instance] = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
plugin.reset = +[](const mjModel* m, mjData* d, int instance) {
|
plugin.reset = +[](const mjModel* m, double* plugin_state, void* plugin_data,
|
||||||
auto passive = reinterpret_cast<TestPassive*>(d->plugin_data[instance]);
|
int instance) {
|
||||||
|
auto passive = reinterpret_cast<TestPassive*>(plugin_data);
|
||||||
passive->Reset();
|
passive->Reset();
|
||||||
};
|
};
|
||||||
plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) {
|
plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user