sdformat icon indicating copy to clipboard operation
sdformat copied to clipboard

Flattening process for nested models modifies unintended elements

Open jennuine opened this issue 4 years ago • 0 comments

Environment

  • Source or binary build? source, sdf9 & sdf10

Description

During the flattening process of an included model, if an element value or attribute has the same value as an element name that requires a name replacement with the :: deliminator then the value of the unintended element or attribute will be changed as well. For example,

<!-- original model -->
<model name='box'>
  <static>1</static>
  <link name='1'>
    ...
  </link>
</model>

<!-- becomes -->
<model name='box'>
  <static>box::1</static>
  <link name='box::1'>
    ...
  </link>
</model>

This happens in the replace_all calls in addNestedModel: https://github.com/ignitionrobotics/sdformat/blob/1a0544467c3a33d2f7b9b71e05f40a1c893bc7ab/src/parser.cc#L1358-L1373

And for this particular example, will lead to Error [Param.cc:319] Invalid boolean value from readXml since the value of <static> is now box::1 (i.e., _xml->GetText() is box::1): https://github.com/ignitionrobotics/sdformat/blob/1a0544467c3a33d2f7b9b71e05f40a1c893bc7ab/src/parser.cc#L944

The logic needs to be addressed so that unintended elements/attributes are not modified.

Steps to reproduce

  1. Clone https://github.com/jennuine/sdf-flatten-bug
  2. In a terminal, export SDF_PATH=/path/to/repo/sdf-flatten-bug
  3. In a the same terminal, ign sdf -k /path/to/repo/sdf-flatten-bug/include_model.sdf

Output

For the example provided above

Error [Param.cc:319] Invalid boolean value
Error [parser.cc:525] parse as sdf version 1.7 failed, should try to parse as old deprecated format
Error: Error reading element <static>
Error: Error reading element <model>
Error: Unable to parse sdf element[sdf]
Error: A model must have at least one link.
Error: A model must have at least one link.
Error: FrameAttachedToGraph error, Non-LINK vertex with name [__model__] is disconnected; it should have 1 outgoing edge in MODEL attached_to graph.
Error: Graph with __model__ scope has sink vertex named [__model__] when starting from vertex with name [__model__], which is not permitted.
Error: Failed to load a world.

jennuine avatar Nov 12 '21 20:11 jennuine