Closed wirepair closed 4 months ago
The problem is that SaveWithChildren will build a ShapeToIDMap which maps Shape* to an ID. In your loop, the created Shape is deleted at the end of the iteration (when BodyCreationSettings/MeshShapeSettings is destructed). There is a certain chance that in the next iteration, a new Shape will be allocated at the exact same location in memory. This means it will see it as the same shape and not write it to the stream. You need to keep your Shapes, PhysicsMaterials and GroupFilters in memory until everything has been written (or if you're sure there is no sharing possible, you need to clear those maps after every shape on both save and load).
Excellent! Thank you for confirming I was indeed using it wrong :>. I assume simply using Jolt's overriden 'new' when creating the MeshSettings & FloorSettings and stuffing them into a vector until the data is written would be sufficient here, that way they are allocated from unique locations from the heap.
Closing anyways as this fixed my issue, thanks again!
Problem
Hello, I'm trying to debug a strange error when I go to load the serialized
BodyCreationSettings
data from callingSaveWithChildren
. It is very possible I'm doing something wrong here!What I'm trying to do is load an FBX that contains multiple meshes in a loop and serializing it. Then deserializing them in a loop by calling
Result.Get()
from the returned object ofsRestoreWithChildren(...)
. Unfortunately, I get random parts of the mesh failing to load, returning anError reading body creation settings
error message. What's super strange is it fails at different times everytime I reload the test.I did confirm the saved output and loaded output is the same so I must be doing something wrong here!
If it helps I attached the FBX and the serialized output, but I imagine you'll spot what I'm doing wrong in my code :>.
Reproduction steps
include
include <Tests/Shapes/BoxShapeTest.h>
include <Jolt/Physics/Collision/Shape/MeshShape.h>
include <Jolt/Physics/Collision/Shape/BoxShape.h>
include <Jolt/Physics/Collision/Shape/CompoundShape.h>
include <Jolt/Physics/Body/BodyCreationSettings.h>
include
include "ThirdParty/ufbx/ufbx.h"
include <Jolt/Core/StreamWrapper.h>
include
include
include
JPH_IMPLEMENT_RTTI_VIRTUAL(BoxShapeTest) { JPH_ADD_BASE_CLASS(BoxShapeTest, Test) }
void PrintVec3(ofstream &Out, ufbx_vec3 &Vec) { Out << "\tx: " << Vec.x << "\ty: " << Vec.y << "\tz: " << Vec.z; } void BoxShapeTest::Initialize() { std::string File = "D:\Temp\out.log"; auto Out = std::ofstream(File, std::ios::out | std::ios::trunc);
}
result.SetError("Error reading body creation settings");
being returnedEvidence
Here's what it looks like if we don't serialize/deserialize![image](https://github.com/jrouwe/JoltPhysics/assets/1073742/82c651d4-2302-44c6-8c09-520e0629deb3)
Here's a random attempt at loading:![image](https://github.com/jrouwe/JoltPhysics/assets/1073742/7afd297c-1220-4907-9f6f-08204f5e193a)
Here's hitting "R" to reload:![image](https://github.com/jrouwe/JoltPhysics/assets/1073742/ec693b8e-f07a-461a-bfec-fdecae3d90a2)
Here's the FBX I'm trying to load, or the already serialized data if you want to load directly: FBX_Out_Data.zip
Thanks!