Skip to content

Commit dacaa77

Browse files
authored
fix: double reset segfault / fp error (Merge pull request #163 from utn-mi/krack/fix_double_reset)
Fixes and issue where calling reset twice in a row crashes the whole program
2 parents e1ce3c6 + 267d291 commit dacaa77

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

.github/workflows/cpp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Clang build
2727
run: make clangcompile
2828
- name: Clang Tidy
29-
run: clang-tidy-15 -p=build --warnings-as-errors='*' $(find src -name '*.cpp' -o -name '*.cc' -name '*.h')
29+
run: clang-tidy -p=build --warnings-as-errors='*' $(find src -name '*.cpp' -o -name '*.cc' -name '*.h')
3030

3131
build_gcc:
3232
runs-on: ubuntu-latest

.github/workflows/py.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
pythonpackage:
2929
runs-on: ubuntu-latest
3030
env:
31-
CC: clang-15
32-
CXX: clang++-15
31+
CC: clang
32+
CXX: clang++
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3434
steps:
3535
- uses: actions/checkout@v4

python/tests/test_sim_envs.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ def assert_collision(self, info: dict):
5757
class TestSimEnvsTRPY(TestSimEnvs):
5858
"""This class is for testing TRPY sim env functionalities"""
5959

60+
def test_reset(self, cfg, gripper_cfg, cam_cfg):
61+
"""
62+
Test reset functionality.
63+
"""
64+
# TODO:
65+
# - test initial pose after reset.
66+
# - test initial gripper config.
67+
env = fr3_sim_env(
68+
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=None
69+
)
70+
# Test double reset. Regression test. A lot can go wrong when resetting.
71+
env.reset()
72+
env.reset()
73+
6074
def test_zero_action_trpy(self, cfg):
6175
"""
6276
Test that a zero action does not change the state significantly
@@ -169,6 +183,24 @@ def test_collision_guard_trpy(self, cfg, gripper_cfg, cam_cfg):
169183
class TestSimEnvsTquart(TestSimEnvs):
170184
"""This class is for testing Tquart sim env functionalities"""
171185

186+
def test_reset(self, cfg, gripper_cfg, cam_cfg):
187+
"""
188+
Test reset functionality.
189+
"""
190+
# TODO:
191+
# - test initial pose after reset.
192+
# - test initial gripper config.
193+
env = fr3_sim_env(
194+
ControlMode.CARTESIAN_TQuart,
195+
cfg,
196+
gripper_cfg=gripper_cfg,
197+
camera_set_cfg=cam_cfg,
198+
max_relative_movement=None,
199+
)
200+
# Test double reset. Regression test. A lot can go wrong when resetting.
201+
env.reset()
202+
env.reset()
203+
172204
def test_non_zero_action_tquart(self, cfg):
173205
"""
174206
Test that a zero action does not change the state significantly in the tquart configuration
@@ -271,6 +303,20 @@ def test_collision_guard_tquart(self, cfg, gripper_cfg, cam_cfg):
271303
class TestSimEnvsJoints(TestSimEnvs):
272304
"""This class is for testing Joints sim env functionalities"""
273305

306+
def test_reset(self, cfg, gripper_cfg, cam_cfg):
307+
"""
308+
Test reset functionality.
309+
"""
310+
# TODO:
311+
# - test initial pose after reset.
312+
# - test initial gripper config.
313+
env = fr3_sim_env(
314+
ControlMode.JOINTS, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=None
315+
)
316+
# Test double reset. Regression test. A lot can go wrong when resetting.
317+
env.reset()
318+
env.reset()
319+
274320
def test_zero_action_joints(self, cfg):
275321
"""
276322
This is for testing that a certain action leads to the expected change in state

src/sim/camera.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ int SimCameraSet::buffer_size() {
5151
}
5252
void SimCameraSet::clear_buffer() {
5353
std::lock_guard<std::mutex> lock(buffer_lock);
54+
// when we clear the buffer, there is no last image timestep
55+
this->last_ts = 0;
5456
buffer.clear();
5557
}
5658

0 commit comments

Comments
 (0)