Skip to content

Commit

Permalink
[lcm] Hotfix for "Eschew LCM C++ API" (#20137)
Browse files Browse the repository at this point in the history
Previously, when multicast was disabled all operations printed a
warning to the console and then did nothing.  The prior commit
changed that to throw an error instead, which was breaking.

Instead, let LCM still print the console warning but then instead
of throwing provide an inert DrakeLcm instead.
  • Loading branch information
jwnimmer-tri authored Sep 6, 2023
1 parent 04d33bc commit 3ad9a1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit 3ad9a1b

Please sign in to comment.