webots icon indicating copy to clipboard operation
webots copied to clipboard

Crash during PROTO regeneration triggered by nested PROTO in parameter

Open stefaniapedrazzi opened this issue 3 years ago • 3 comments

In the following world, change the Test2.t translation value to make Webots crash.

World:

#VRML_SIM R2021b utf8
WorldInfo {
  coordinateSystem "NUE"
}
Viewpoint {
  orientation 0.3434989325345835 -0.9106458211432591 -0.22963595489801025 5.24359
  position 3.6253302181468703 1.9376211271421955 2.5095511652221436
}
Background {
  skyColor [
    0.4 0.7 1
  ]
}
Test3 {
  slot [
    Test2 {
      t 0.1 0 0
    }
  ]
}

Test3.proto

#VRML_SIM R2021b utf8

PROTO Test3 [
  field MFNode slot []
]
{
Solid {
  children IS slot
}
}

Test2.proto

#VRML_SIM R2021b utf8

PROTO Test2 [
  field SFVec3f t 0 0 0
]
{
Group {
  children [
    Test {
      t IS t
    }
  ]
}
}

Test.proto

#VRML_SIM R2021b utf8

PROTO Test [
  field SFVec3f t 0 0 0
]
{

  Transform {
    translation %{=fields.t.value.x}% %{=fields.t.value.y}% %{=fields.t.value.z}%
    children [
      Shape {
        geometry Box {
        }
      }
    ]
  }
}

stefaniapedrazzi avatar Jun 28 '21 14:06 stefaniapedrazzi

I tested with R2022a (Ubuntu 20.04) and I could not reproduce the crash. However, there is still a bug because the position of the box is not updated and Webots sometimes freeze several seconds when I change the t value.

BenjaminDeleze avatar Jun 15 '22 06:06 BenjaminDeleze

My bad, it crashed in debug mode because this assert failed:

vrml/WbNode.cpp:123: void WbNode::setUniqueId(int): Assertion 'gRestoreUniqueIdOnClone || gNodes[newId] == NULL'

BenjaminDeleze avatar Jun 16 '22 09:06 BenjaminDeleze

I did not managed to fix the problem but here is where I am so far:

  • It crashes in WbNode::setUniqueId. We try to give the id of the old node to the newly generated one. However, the old one was not deleted (or at least not correctly)
  • The old node should have been deleted in WbTemplateManager::regenerateNode before the call to setUniqueId.
    • The node enters the condition node->isProtoParameterNode(). However, the parentField of the node is detected as a vector3 (it is the t field)! So neither a WB_SF_NODE nor a WB_MF_NODE
    • Thus, we enter no condition and we just continue without deleting the node.

I think the problem is here: we do not detect the right parent field

BenjaminDeleze avatar Jun 17 '22 15:06 BenjaminDeleze