NVIDIAGameWorks / PhysX-3.4

NVIDIA PhysX SDK 3.4
https://www.nvidia.com/
2.35k stars 274 forks source link

Crash in AABBPruner::visualize #13

Closed sagaceilo closed 7 years ago

sagaceilo commented 7 years ago

Hello,

I'm getting crash when building visualization buffer. It happens when some object moves (there is a few frames of working debug visualizer, when nothing moves). I'm doing gathering of debugBuffer after fetch with lockRead/unlockRead just to be sure, there is no race.

I'm using newset PhysX 3.4 code.

Callstack:

`visualizeTree'::`5'::Local::_Draw(const physx::Sq::AABBTreeRuntimeNode * root, const physx::Sq::AABBTreeRuntimeNode * node, physx::Cm::RenderOutput & out_) Line 775   C++
physx::Sq::ExtendedBucketPruner::visualize(physx::Cm::RenderOutput & out, unsigned int color) Line 790  C++
physx::Sq::AABBPruner::visualize(physx::Cm::RenderOutput & out, unsigned int color) Line 544    C++
physx::NpScene::visualize() Line 1540   C++
physx::NpScene::simulateOrCollide(float elapsedTime, physx::PxBaseTask * completionTask, void * scratchBlock, unsigned int scratchBlockSize, bool controlSimulation, const char * invalidCallMsg, physx::Sc::SimulationStage::Enum simStage) Line 1967  C++
physx::NpScene::simulate(float elapsedTime, physx::PxBaseTask * completionTask, void * scratchBlock, unsigned int scratchBlockSize, bool controlSimulation) Line 2049   C++

SqExtendedBucketPruner.cpp [775]

void visualizeTree(Cm::RenderOutput& out, PxU32 color, AABBTree* tree)
{
    if (tree)
    {
        struct Local
        {
            static void _Draw(const AABBTreeRuntimeNode* root, const AABBTreeRuntimeNode* node, Cm::RenderOutput& out_)
            {
                out_ << Cm::DebugBox(node->mBV, true);   // <<< CRASH, root and node is nullptr
                if (node->isLeaf())
                    return;
                _Draw(root, node->getPos(root), out_);
                _Draw(root, node->getNeg(root), out_);
            }
        };
        out << PxTransform(PxIdentity);
        out << color;
        Local::_Draw(tree->getNodes(), tree->getNodes(), out);
    }
}

mMainTree seems to be empty : http://i.imgur.com/yZ1DYFS.png

sagaceilo commented 7 years ago

Changing line 769 to:

if (tree && tree->getNodes())

Fixed problem.

PierreTerdiman commented 7 years ago

Thank you for the bug report. This is a bug indeed, and your fix is good. I added it to our trunk.

sagaceilo commented 7 years ago

Thank you for quick respone :) I'm glad it helped.

There is similar code here: SqAABBPruner.cpp [ line 521 ]

void AABBPruner::visualize(Cm::RenderOutput& out, PxU32 color) const
{
    // ...
    if( tree ) // <<<< HERE
    {
        struct Local
        {
            static void _Draw(const AABBTreeRuntimeNode* root, const AABBTreeRuntimeNode* node, Cm::RenderOutput& out_)
            {
            // ...
            }
        };
        //...
        Local::_Draw(tree->getNodes(), tree->getNodes(), out);
    }
    // ...
}

It can be changed to similar check I proposed earlier. Seems like potential bug also. I've never got crash at this code path, but You never know...

PierreTerdiman commented 7 years ago

Yes, I saw it and fixed both places :)

sagaceilo commented 7 years ago

Thats cool, thanks again ;)