diff --git a/src/cpp/fastdds/publisher/PublisherImpl.cpp b/src/cpp/fastdds/publisher/PublisherImpl.cpp index af141c90e81..8a46c23fe08 100644 --- a/src/cpp/fastdds/publisher/PublisherImpl.cpp +++ b/src/cpp/fastdds/publisher/PublisherImpl.cpp @@ -245,22 +245,25 @@ DataWriter* PublisherImpl::create_datawriter( } // Check netmask filtering preconditions - fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( - rtps_participant()->getGuid()); - if (nullptr != rtps_impl) - { - std::vector netmask_filter_info = - rtps_impl->network_factory().netmask_filter_info(); - std::string error_msg; - if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().ignore_non_matching_locators, - error_msg) || - !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().external_unicast_locators, error_msg)) + if (nullptr != rtps_participant()) + { + fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( + rtps_participant()->getGuid()); + if (nullptr != rtps_impl) { - EPROSIMA_LOG_ERROR(PUBLISHER, - "Failed to create publisher -> " << error_msg); - return nullptr; + std::vector netmask_filter_info = + rtps_impl->network_factory().netmask_filter_info(); + std::string error_msg; + if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().ignore_non_matching_locators, + error_msg) || + !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().external_unicast_locators, error_msg)) + { + EPROSIMA_LOG_ERROR(PUBLISHER, + "Failed to create publisher -> " << error_msg); + return nullptr; + } } } diff --git a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp index e1d223b83b5..ed4d2b1dfb4 100644 --- a/src/cpp/fastdds/subscriber/SubscriberImpl.cpp +++ b/src/cpp/fastdds/subscriber/SubscriberImpl.cpp @@ -214,22 +214,25 @@ DataReader* SubscriberImpl::create_datareader( } // Check netmask filtering preconditions - fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( - rtps_participant()->getGuid()); - if (nullptr != rtps_impl) - { - std::vector netmask_filter_info = - rtps_impl->network_factory().netmask_filter_info(); - std::string error_msg; - if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().ignore_non_matching_locators, - error_msg) || - !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, - qos.endpoint().external_unicast_locators, error_msg)) + if (nullptr != rtps_participant()) + { + fastrtps::rtps::RTPSParticipantImpl* rtps_impl = fastrtps::rtps::RTPSDomainImpl::find_local_participant( + rtps_participant()->getGuid()); + if (nullptr != rtps_impl) { - EPROSIMA_LOG_ERROR(SUBSCRIBER, - "Failed to create subscriber -> " << error_msg); - return nullptr; + std::vector netmask_filter_info = + rtps_impl->network_factory().netmask_filter_info(); + std::string error_msg; + if (!fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().ignore_non_matching_locators, + error_msg) || + !fastdds::rtps::NetmaskFilterUtils::check_preconditions(netmask_filter_info, + qos.endpoint().external_unicast_locators, error_msg)) + { + EPROSIMA_LOG_ERROR(SUBSCRIBER, + "Failed to create subscriber -> " << error_msg); + return nullptr; + } } }