RepX deserialization leads to access violation in PhysX SDK 3.2.2

Hi,
I’m trying to deserialize a simple box object I exported from the 3ds max 2013 PhysX plugin, and everything seems to go fine, but then I get an access violation during some memory allocation thing in the PhysX worker thread.
Am I doing something wrong here?
PhysX SDK 3.2.2 on x86, VS 2012

PxPhysics* physics = gEngine->getPhysics()->getPhysics();
    PxCooking* cooking = gEngine->getPhysics()->getCooking();
    PxScene* scene = mWorld->getPhysical()->getScene();

    PxCollection* buffers = physics->createCollection();
    PxCollection* objects = physics->createCollection();

    assert( scene != NULL && physics != NULL && cooking != NULL && buffers != NULL && objects != NULL );
    PxDefaultFileInputData data( "dev_obj_test1.RepX" );
    assert( data.isValid() );
    assert( repx::deserializeFromRepX( data, *physics, *cooking, NULL, NULL, *buffers, *objects, NULL ) == repx::RepXErrorCode::eSuccess );
    float nf = 40.0f;
    physics->addCollection( *buffers, *scene );
    physics->addCollection( *objects, *scene );
    for ( PxU32 i = 0; i < objects->getNbObjects(); i++ ) {
      PxActor* actor = objects->getObject( i )->is();
      gEngine->getConsole()->printf( srcPhysics, L"Importing: %S", objects->getObject( i )->getConcreteTypeName() );
      if ( actor && actor->isRigidDynamic() ) {
        PxRigidDynamic* d = (PxRigidDynamic*)actor;
        PxTransform pose( PxVec3( 0.0f, nf, 5.0f ) );
        d->setGlobalPose( pose, true );
        nf += 1.0f;
      }
    }
    objects->release();
    buffers->release();

I’ve tried not doing the posing loop, I’ve tried not releasing the collections, and I’ve tried not adding the buffers collection. I’ve also tried with both a convex mesh and a simple Box shape in the RepX, nothing matters. I get an access violation in the worker thread PxWorker00.
Call stack:

PhysX3_x86.dll!503c4d39()	Unknown
 	PhysX3_x86.dll!503c9a72()	Unknown
 	PhysX3_x86.dll!503c5ebd()	Unknown
 	PhysX3_x86.dll!503c66ce()	Unknown
 	PhysX3_x86.dll!503c6ad5()	Unknown
 	PhysX3_x86.dll!503bb6eb()	Unknown
 	kernel32.dll!_HeapFree@12()	Unknown
>	msvcr110d.dll!_unlock(int locknum) Line 366	C
 	Game.exe!physx::PxDefaultAllocator::allocate(unsigned int size, const char * __formal, const char * __formal, int __formal) Line 61	C++
 	PhysX3Common_x86.dll!50173b41()	Unknown
 	PhysX3_x86.dll!503b8119()	Unknown
 	PhysX3_x86.dll!503b8125()	Unknown
 	PhysX3Common_x86.dll!50171b4e()	Unknown
 	Game.exe!physx::Ext::CpuWorkerThread::execute(void)	Unknown

The access violation happens in VCRT’s mlock.c function _lock, where it tries to compare data from a bad array index to null:

/*
         * Create/open the lock, if necessary
         */
        if ( _locktable[locknum].lock == NULL ) {

            if ( !_mtinitlocknum(locknum) )
                _amsg_exit( _RT_LOCK );
        }

        // locknum is 256, which is out of bounds for the array -> access violation

Can you try this?

PxAggregate *agg = createAggregate();
getScene().addAggregate( *agg );

PxCollection* collection = getPhysics().createCollection();

PxToolkit::MemoryOutputStream outData;
PxCollectForExportSDK(getPhysics(), *collection);
PxCollectForExportScene(getScene(), *collection);

PxU32 oriNum = collection->getNbObjects();
PxU64 addrBegin = 0x80000000;
serializeToRepX(outData, *collection, addrBegin);

collection->release();

PxToolkit::MemoryInputData inData(outData.getData(), outData.getSize());

PxCollection* shared = getPhysics().createCollection();;
PxCollection* instanced = getPhysics().createCollection();;
PxUserReferences * userRefs = getPhysics().createUserReferences();
RepXErrorCode::Enum errCocde = deserializeFromRepX(inData, getPhysics(), getFactory().getCooking(), NULL, 0, *shared, *instanced, [b]userRefs[/b]);


shared->release();
instanced->release();
userRefs->release();

Hey, I tried doing what you asked, but it’s just not working out.
When I try to include the PxToolkit headers that this code requires, my whole project goes crazy with compilation errors.
Somehow those headers break my projet’s namespace/objects, and I don’t really know what’s going on at all.

Do you suppose my problems could be because I’m using Visual Studio 2012…? The PhysX libraries don’t seem, so far, to go very well together with VS2012.
For now I’m trying out the freshly compiled 3.2.3 libraries talked about here, and playing around with the runtime library settings, in the hope that it would resolve this access violation as well.

Well, nope, new libraries & static runtime did not help. Open to ideas still.

Hi,

I’ve tested your edited code in our samples in VS2012 with the patched 3.2.3 package.

Edited code:
PxPhysics& physics = getPhysics();
//PxCooking& cooking = getCooking();
PxScene& scene = getActiveScene();

PxCollection* buffers = physics.createCollection();
PxCollection* objects = physics.createCollection();

//assert( scene != NULL && physics != NULL && cooking != NULL && buffers != NULL && objects != NULL );
PxDefaultFileInputData data( "test.repx" );
assert( data.isValid() );
assert( repx::deserializeFromRepX( data, physics, getCooking(), NULL, NULL, *buffers, *objects, NULL ) == repx::RepXErrorCode::eSuccess );

physics.addCollection( *buffers, scene );
physics.addCollection( *objects, scene );

objects->release();
buffers->release();

Put this in SampleHelloWorld.cpp after PhysXSample::onInit(). The test.repx file is placed in the bin/win32 folder. It all seems fine.

Please try this in our samples and probably you could debug it from there too.

Thanks,
-Sheikh

Well, the sample isn’t crashing, but neither is my object showing up in the simulation. I don’t really know how the sample framework works, so I don’t know what to do about that.

However, I also don’t really know what there is for me to debug. My application’s init procedure, regarding PhysX, is just like in the samples, and then I get an obscure crash in your memory allocator. None of the other ~10 libraries my application uses have had any problems since I moved to VS2012.

I guess I’ll try using my own allocator, to see if that matters at all.

EDIT: Yeah, no, did not help at all.