diff --git a/src/cpp/fastdds/xtypes/dynamic_types/DynamicTypeBuilderFactoryImpl.cpp b/src/cpp/fastdds/xtypes/dynamic_types/DynamicTypeBuilderFactoryImpl.cpp index 2b1df2c7076..94e7af98ee9 100644 --- a/src/cpp/fastdds/xtypes/dynamic_types/DynamicTypeBuilderFactoryImpl.cpp +++ b/src/cpp/fastdds/xtypes/dynamic_types/DynamicTypeBuilderFactoryImpl.cpp @@ -607,22 +607,24 @@ traits::ref_type DynamicTypeBuilderFactoryImpl::create_struc type_descriptor.extensibility_kind(struct_type.struct_flags() & xtypes::IS_FINAL ? ExtensibilityKind::FINAL : (struct_type.struct_flags() & xtypes::IS_MUTABLE ? ExtensibilityKind::MUTABLE : ExtensibilityKind::APPENDABLE)); - - ret_val = std::make_shared(type_descriptor); - + bool inheritance_correct {true}; if (xtypes::TK_NONE != struct_type.header().base_type()._d()) { traits::ref_type base_type = base_type_from_type_identifier(struct_type.header().base_type()); if (base_type) { - ret_val->get_descriptor().base_type(base_type); + type_descriptor.base_type(base_type); } else { EPROSIMA_LOG_ERROR(DYN_TYPES, "Inconsistent base TypeIdentifier"); - ret_val.reset(); + inheritance_correct = false; } } + if (inheritance_correct) + { + ret_val = std::make_shared(type_descriptor); + } if (ret_val) {