[SOLVED]Crash on VaoManager destroy calls

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

[SOLVED]Crash on VaoManager destroy calls

Post by IndieGuy11 »

Hey, I did not edit the old post because this is unrelated ...

However, whenever I am calling destroyIndexBuffer, destroyVertexBuffer, I am crashing on delete (i traced it)

destroyVertexArrayObject seems to not crash. I am saving all of them in a vector so I know they are valid.

In the example, I dont see where this is done, so I wondering if I have to take care of it ...

Thanks!
Last edited by IndieGuy11 on Fri Sep 08, 2017 7:52 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Crash on VaoManager destroy calls

Post by dark_sylinc »

Could you post the deletion code and the callstack? Thanks
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: Crash on VaoManager destroy calls

Post by IndieGuy11 »

Okay! Hopefully I am not using it wrong (and I am also not mixing up any pointers and what not!) ... But the example does not do any of this. Its also possible its on my end too ^^. Thanks for your time! Just trying to help make Ogre Better!

Creation:

Code: Select all

std::vector<Ogre::VertexBufferPacked*> m_VertexBuffer;
Ogre::VertexBufferPacked* tempVertexBuffer = nullptr;
            try
            {
                tempVertexBuffer = vaoManager->createVertexBuffer(vertexElements,
                    tempVertexSize,
                    Ogre::BT_IMMUTABLE,
                    cmd_list->VtxBuffer.Data, true);
                m_VertexBuffer.push_back(
                    tempVertexBuffer
                );
            }
... dadada

Looping, not sure if i can do this. I keep the pointer to the vb because of loop making vertexes and what not (same as index)

Code: Select all

std::vector<Ogre::VertexArrayObject*> m_Vao;
Ogre::VertexBufferPackedVec packedVertexBuffers;
packedVertexBuffers.push_back(m_VertexBuffer[i]);
Ogre::VertexArrayObject *tempVao = vaoManager->createVertexArrayObject(packedVertexBuffers, m_IndexBuffer[i], Ogre::OT_TRIANGLE_LIST);
m_Vao.push_back(tempVao);
mVaoPerLod[0].push_back(tempVao);
// deletion

Code: Select all

Ogre::VaoManager* vaoManager = mManager->getDestinationRenderSystem()->getVaoManager();
        for (auto itVao = m_Vao.begin(); itVao != m_Vao.end(); ++itVao)
        {
            Ogre::VertexArrayObject* vao = *itVao;
            if (vao)
            {
                const Ogre::VertexBufferPackedVec &vertexBuffers = vao->getVertexBuffers();
                for (auto itVB = vertexBuffers.begin(); itVB != vertexBuffers.end(); ++itVB)
                {
                    Ogre::VertexBufferPacked* vertexBuffer = *itVB;
                    if (vertexBuffer->getMappingState() != Ogre::MS_UNMAPPED)
                    {
                        vertexBuffer->unmap(Ogre::UO_UNMAP_ALL);
                    }
                    vaoManager->destroyVertexBuffer(vertexBuffer);
                }
            }
        }
And if I do it another way(I saved them), same thing happens:

Code: Select all

for (auto itVB = m_VertexBuffer.begin(); itVB != m_VertexBuffer.end(); ++itVB)
        {
            Ogre::VertexBufferPacked* vertexBuffer = *itVB;
            if (vertexBuffer->getMappingState() != Ogre::MS_UNMAPPED)
            {
                vertexBuffer->unmap(Ogre::UO_UNMAP_ALL);
            }
            vaoManager->destroyVertexBuffer(vertexBuffer);
        }

Code: Select all

 	ntdll.dll!00007ffb7da1c5ae()	Unknown	Non-user code. Cannot find or open the PDB file.
 	ntdll.dll!00007ffb7d9e820c()	Unknown	Non-user code. Cannot find or open the PDB file.
 	ntdll.dll!00007ffb7d997a4f()	Unknown	Non-user code. Cannot find or open the PDB file.
 	KernelBase.dll!00007ffb7a3f71ba()	Unknown	Non-user code. Cannot find or open the PDB file.
 	ucrtbased.dll!00007ffb43b6d0d1()	Unknown	Non-user code. Cannot find or open the PDB file.
 	ucrtbased.dll!00007ffb43b6b4d5()	Unknown	Non-user code. Cannot find or open the PDB file.
 	ucrtbased.dll!00007ffb43b6eac5()	Unknown	Non-user code. Cannot find or open the PDB file.
>	OgreMain_d.dll!operator delete(void * block) Line 21	C++	Non-user code. Symbols loaded.
 	OgreMain_d.dll!operator delete[](void * block) Line 16	C++	Non-user code. Symbols loaded.
 	OgreMain_d.dll!Ogre::AlignedMemory::deallocate(void * p) Line 79	C++	Symbols loaded.
 	OgreMain_d.dll!Ogre::StdAlignedAllocPolicy<0>::deallocateBytes(void * ptr) Line 137	C++	Symbols loaded.
 	OgreMain_d.dll!Ogre::BufferPacked::~BufferPacked() Line 104	C++	Symbols loaded.
 	OgreMain_d.dll!Ogre::VertexBufferPacked::~VertexBufferPacked() Line 54	C++	Symbols loaded.
 	[External Code]		Annotated Frame

Crash Location:

Code: Select all

void VaoManager::destroyVertexBuffer( VertexBufferPacked *vertexBuffer )
    {
        if( vertexBuffer->getMultiSourcePool() )
        {
            OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
                         "Vertex Buffer belongs to a Multisource pool, not this VaoManager",
                         "VaoManager::destroyVertexBuffer" );
        }

        BufferPackedSet::iterator itor = mBuffers[ BP_TYPE_VERTEX ].find( vertexBuffer );

        if( itor == mBuffers[BP_TYPE_VERTEX].end() )
        {
            OGRE_EXCEPT( Exception::ERR_INVALID_STATE,
                         "Vertex Buffer has already been destroyed or "
                         "doesn't belong to this VaoManager.",
                         "VaoManager::destroyVertexBuffer" );
        }

        if( vertexBuffer->getBufferType() >= BT_DYNAMIC_DEFAULT )
        {
            //We need to delay the removal of this buffer until
            //we're sure it's not in use by the GPU anymore
            DelayedBuffer delayedBuffer( vertexBuffer, mFrameCount, mDynamicBufferCurrentFrame );
            mDelayedDestroyBuffers.push_back( delayedBuffer );
        }
        else
        {
            destroyVertexBufferImpl( vertexBuffer );
            OGRE_DELETE vertexBuffer;
        }

        mBuffers[ BP_TYPE_VERTEX ].erase( itor );
    }
Crash.
OGRE_DELETE vertexBuffer;

EDIT:
It only crashes if createVertexBuffer, keepAsShadow= true

I guess I was using it wrong! Sorry ><!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Crash on VaoManager destroy calls

Post by dark_sylinc »

IndieGuy11 wrote:EDIT:
It only crashes if createVertexBuffer, keepAsShadow= true

I guess I was using it wrong! Sorry ><!
I'm glad you worked it out :)

As per the documentation in BufferPacked::BufferPacked (bolded parts are relevant/important):
@param keepAsShadow
Keeps "intialData" as a shadow copy for reading from CPU without querying the GPU
(can be useful for reconstructing buffers on device/context loss or for efficient
reading of the data without streaming back from GPU.)

If keepAsShadow is false, caller is responsible for freeing the data

If keepAsShadow is true, we're responsible for freeing the pointer. We will free the
pointer using OGRE_FREE_SIMD( MEMCATEGORY_GEOMETRY ), in which case the pointer
*must* have been allocated using OGRE_MALLOC_SIMD( MEMCATEGORY_GEOMETRY )

If the constructor throws, then data will NOT be freed, and caller will have to do it.
@see FreeOnDestructor to help you with exceptions and correctly freeing the data.


Must be false if bufferType >= BT_DYNAMIC
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: Crash on VaoManager destroy calls

Post by IndieGuy11 »

Thanks! I also assume, that i can not pushback multiple VertexArrayObjects into mVaoPerLod[0]? Or can you? Seems like the GUI wont render correctly unless I do each pass with a new Renderable Object rather than 1 Renderable Object!
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Crash on VaoManager destroy calls

Post by dark_sylinc »

IndieGuy11 wrote:Thanks! I also assume, that i can not pushback multiple VertexArrayObjects into mVaoPerLod[0]? Or can you? Seems like the GUI wont render correctly unless I do each pass with a new Renderable Object rather than 1 Renderable Object!
That system is meant for LODs, so only one VertexArrayObject from mVaoPerLod[0] will be selected for rendering.
It is MovableObject::mRenderables vector what controls how many Renderables to use per MovableObject. The default sample performs mRenderables.push_back( this ); because MyCustomRenderable for simplicity is both a MovableObject and a Renderable, however it is possible to have them as separate classes.

For reference: A MovableObject has its own position, rotation, scale when attached to a SceneNode, and its own AABB (for culling). A renderable has its own geometry (a VertexArrayObject) and its own material (an Hlms datablock).
IndieGuy11
Halfling
Posts: 50
Joined: Fri May 19, 2017 8:09 pm
x 2

Re: [SOLVED]Crash on VaoManager destroy calls

Post by IndieGuy11 »

Okay! Makes sense. I dont see any benefit in doing it then.

Thank you! :D :D :D :D :D :D :D :D :D :D :D :D
Post Reply