Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lcm] Hotfix for "Eschew LCM C++ API" #20137

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lcm/drake_lcm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ class DrakeLcm::Impl {
// Create the native instance only after all other checks are finished.
lcm_ = ::lcm_create(lcm_url_.c_str());
if (lcm_ == nullptr) {
throw std::runtime_error("Failure on lcm_create()");
// The initialization failed and printed a console warning. Create
// a dummy object instead (to at least have something non-null).
lcm_ = ::lcm_create("memq://");
DRAKE_THROW_UNLESS(lcm_ != nullptr);
}
}

Expand Down
6 changes: 6 additions & 0 deletions lcm/test/drake_lcm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ TEST_F(DrakeLcmTest, CustomUrlTest) {
EXPECT_EQ(dut_->get_lcm_url(), kUdpmUrl);
}

TEST_F(DrakeLcmTest, BadUrlTest) {
// At the moment, invalid URLs print to the console but do not throw.
// We probably want to revisit this as some point (to fail-fast).
EXPECT_NO_THROW(DrakeLcm("no-such-scheme://foo"));
}

TEST_F(DrakeLcmTest, DeferThreadTest) {
DrakeLcmParams params;
params.lcm_url = kUdpmUrl;
Expand Down