Skip to content

Commit c68b8b6

Browse files
authored
Fixed clean-up of the motion library causing problems with the Python API (#6029)
* Fixed clean-up of the motion library causing problems with the Python API * Change log * Use ROBOT_ASSERT instead of assert * Fixed compilation
1 parent f703d02 commit c68b8b6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docs/reference/changelog-r2023.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Released on ??
1212
- Improved default selected tab in Field Editor when nodes are selected ([#5726](https://github.com/cyberbotics/webots/pull/5726)).
1313
- Change the Windows version of SUMO to 1.13 to match the one used on Linux and MacOS and avoid a potiental Log4J vulnerability ([#6010](https://github.com/cyberbotics/webots/pull/6010)).
1414
- Bug Fixes
15+
- Fixed the clean-up of the motion API which was firing warnings in Python ([#6029](https://github.com/cyberbotics/webots/pull/6029)).
1516
- Fixed the behavior of the [Connector](connector.md) after a reset to return to the controller the correct status ([#5889](https://github.com/cyberbotics/webots/pull/5889))
1617
- Fixed redirection of stdout/stderr for Python controllers on Windows ([#5807](https://github.com/cyberbotics/webots/pull/5807)).
1718
- Fixed crash in Python API when a robot controller was using several cameras with different resolutions ([#5705](https://github.com/cyberbotics/webots/pull/5705)).

src/controller/c/motion.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static const double UNDEFINED_POSITION = -9999999.9;
5050
static WbMotionRef head = NULL;
5151
static const char *HEADER = "#WEBOTS_MOTION";
5252
static const char *VERSION = "V1.0";
53+
static int cleanup_done = 0;
5354

5455
// string to time conversion
5556
// acceptable input format: [[Minutes:]Seconds:]:Milliseconds
@@ -382,6 +383,7 @@ void motion_cleanup() {
382383
wbu_motion_delete(head);
383384

384385
ROBOT_ASSERT(head == NULL);
386+
cleanup_done = 1;
385387
}
386388

387389
// Webots API functions below
@@ -451,10 +453,12 @@ WbMotionRef wbu_motion_new(const char *filename) {
451453
void wbu_motion_delete(WbMotionRef motion) {
452454
if (!motion)
453455
return;
454-
455456
// dequeue self
456457
if (!motion_dequeue(motion)) {
457-
fprintf(stderr, "Error: %s(): attempt to delete an invalid 'motion'.\n", __FUNCTION__);
458+
if (cleanup_done) { // the Python API calls first motion_cleanup and then tries to delete motion files.
459+
ROBOT_ASSERT(head == NULL); // no new motion should have been created after the cleanup.
460+
} else
461+
fprintf(stderr, "Error: %s(): attempt to delete an invalid 'motion'.\n", __FUNCTION__);
458462
return;
459463
}
460464

0 commit comments

Comments
 (0)