Make context initialization and destruction more robust #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when you run e.g.
ros2 run rclrs_examples minimal_publisher --ros-args -r __node:=my/node
, which is an invalid node name, you'll get a messageThis is fixed by checking that the context is indeed valid before calling
rcl_shutdown()
andrcl_context_fini()
on it, becausercl_init()
leaves the context in an invalid/zero-initialized state when it returns an error. (This is a separate issue from not resetting the error state, which we'll also do soon.)Furthermore, the
Context::new
method had an unnecessary dance where the rcl_context is put in a mutex and taken out again.I also made a tiny change so that the error code is converted to a Result right after the call, in anticipation of
rcl_init_options_fini(&mut init_options).ok()?
possibly overwriting the error state.