u3d-community / U3D

Open-source, cross-platform 2D and 3D game engine built in C++
https://u3d.io
MIT License
154 stars 26 forks source link

Attributes bug #66

Open nimdavirus opened 3 weeks ago

nimdavirus commented 3 weeks ago

If you save the scene in binary format and then create a new attribute in the component, then a crash will occur when loading the scene. There is no such thing with the text format of the scene.

eugeneko commented 3 weeks ago

Urho binary format is not safe (and was never safe) if serializable layout changes:

https://github.com/u3d-community/U3D/blob/master/Source/Urho3D/Scene/Serializable.cpp#L334

You must have the same attributes of the exact type in the exact order on save and load.

We have solved it by serializing StringHash+VariantType of attributes together with the value.

nimdavirus commented 2 weeks ago

Urho binary format is not safe (and was never safe) if serializable layout changes:

https://github.com/u3d-community/U3D/blob/master/Source/Urho3D/Scene/Serializable.cpp#L334

You must have the same attributes of the exact type in the exact order on save and load.

We have solved it by serializing StringHash+VariantType of attributes together with the value.

Can you show me an example please?

eugeneko commented 2 weeks ago

@nimdavirus I can show you our code that does this task, but it is completely disconnected from current U3D codebase. I didn't want to share it initially because I didn't consider it helpful.

https://github.com/rbfx/rbfx/blob/master/Source/Urho3D/Scene/NodePrefab.cpp#L87-L126

nimdavirus commented 2 weeks ago

@nimdavirus I can show you our code that does this task, but it is completely disconnected from current U3D codebase. I didn't want to share it initially because I didn't consider it helpful.

https://github.com/rbfx/rbfx/blob/master/Source/Urho3D/Scene/NodePrefab.cpp#L87-L126

I will use VariantVector in attributes for proper binary file serialization