Skip to content

Serialization of a std::map<std::string, ChLinkTSDA> leads to a segmentation fault #507

Open
@paulotto

Description

@paulotto

Hi everyone,

I tried to serialize a class member of type std::map<std::string, ChLinkTSDA> with archive_out << CHNVP(map_);, but unfortunately, this led to a segmentation fault.

While looking for the cause of this, I came across another issue, which I wondered if was related to the first issue. If you want to do something like this

std::map<std::string, ChLinkTSDA> map_{
    {"l1", ChLinkTSDA()}
};

a 'bad_alloc' exception is thrown. I could eliminate this by adding the following line to the copy constructor of ChLinkTSDA:

m_jacobians = other.m_jacobians ? new SpringJacobians(*other.m_jacobians) : nullptr;

and change the copying of m_variables to:

m_variables = other.m_variables ? new ChVariablesGenericDiagonalMass(*other.m_variables) : nullptr;

But in the end, I couldn't solve the serialization problem. Maybe you have a solution.

Thanks and best regards,
Paul

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions