How to load PxCollection from file? PhysX 3.2.0

Hi, I have a problem with load a PxCollection.

PxCollection *c = gPhysicsSDK->createCollection();
				actor->collectForExport(*c);
				PxToolkit::FileOutputStream stream("col.bin");
				
				c->serialize(stream);
				c->release();

Now I want to load for example “col.bin” file and add collection to scene. How to define void* 128-bytes aligned buffer?

PxCollection *c = pPhx->gPhysicsSDK->createCollection();
				PxToolkit::FileInputData reads("col.bin");

				c->deserialize( ?? void* buffer128 ?? , NULL, NULL);

Hello,

The PxToolkit::FileInputData can’t be used for binary deserialization. The whole collection data needs to be loaded into a block of 128 byte aligned memory before calling PxCollection::deserialize.

Here is an example how you could do it:

PxCollection *c = pPhx->gPhysicsSDK->createCollection();
void* collectionBuffer = NULL;

FILE* fp = fopen("col.bin", "rb");
if(fp)
{
	unsigned fileSize = GetFileSize(filename);
	collectionBuffer = malloc(fileSize+PX_SERIAL_FILE_ALIGN);
	void* buffer128 = (void*)((size_t(buffer) + PX_SERIAL_FILE_ALIGN)&~(PX_SERIAL_FILE_ALIGN-1));
	fread(buffer128, 1, fileSize, fp);
	fclose(fp);
	c->deserialize(buffer128, NULL, NULL);
}

Make sure to not realease the memory containing the collection objects (collectionBuffer) before you have released all the objects in the collection (whenever you don’t need your PhysX objects anymore).

Unfortunately I get an error.
…\PhysX\src\NpPhysics.cpp (948) : invalid parameter : Buffer contains data with wrong header indicating invalid binary data.

Could you check whats in col.bin right after calling c->serialize(stream); ?
The first 4 bytes should contain the bytes corresponding to the chars ‘S’ ‘E’ ‘B’ ‘D’ which is the header of the data expected.

I opened file using notepad. First line starts with:

SEBD  PC32

At this point I don’t have a good idea what could be going wrong. Would it be possible to create a little repro with source and attach it here?