1

I made a custom mesh class inherited Qt3DRender::QGeometryRenderer to draw lines in Qt3D and use it in the same way as Qt3DExtras::QShpereMesh or others. Here the source( .h , .cpp ) And on test with single line creation everithing as i expected, line creates and destroy without an error. But if do test with std::vector<Qt3DCore::QEntity*> and put to it 100 Qt3DCore::QEntity* and add them line as a component i have heap error.(here test project)

Version of Qt:6.1.0.

In Visual Studio 2019 CE with DEBUG 64bit build the runtime error message is:

HEAP[QLineMesh_test.exe]: Invalid address specified to RtlValidateHeap( 0000013BF0630000, 0000013BF522D060 ) QLineMesh_test.exe has triggered a breakpoint. and VS points to breakpoint line in file debug_heap.cpp:

// This function is provided for backwards compatibility only.  It returns TRUE
// if the given block points to an allocation from the OS heap that underlies
// this CRT debug heap.  Back when the CRT used its own OS heap (prior to Dev10),
// this function would thus also tell you whether the block was allocated by this
// debug heap.  Now, it just tells you whether the block was allocated by some
// debug heap.
extern "C" int __cdecl _CrtIsValidHeapPointer(void const* const block)
{
    if (!block)
        return FALSE;

    return HeapValidate(__acrt_heap, 0, header_from_block(block));  ///<-----breakpoint here on HeapValidate
}

In VS RELEASE 64bit build breakpoint is in qarraydata.h at QArrayData::reallocateUnaligned function call.

In QtCreator with MSVC2019 64bit and minGW64-bit builds program terminated after same behaviour but without such deep explanation.

May be the error happen in function which generate the vertex data of mesh and put it to QByteArray for later usage in Qt3DCore::QBuffer.The fragment code of function from here:

inline void QLineMesh::generateVertexData()
{
    ...
    vertex_buf.clear();
    
    vertex_buf.resize((3 + 3) * 6 * sizeof(float));
    float* possitions = reinterpret_cast<float*>(vertex_buf.data());
    int index = 0;

    for (auto& v : vertices)
    {
        possitions[index++] = v.x();
        possitions[index++] = v.y();
        possitions[index++] = v.z();
    }

};

I can`t imagene how the heap can be affected by this mesh creation class if it's just store pointers and logic to how to manage it.

UPDATE: In Qt 5.15.2 everithing works as expected without errors. Source in question support both versions.

  • This is probably a bit beyond Stack Overflow when it needs to take the project and debug. There so many unsafe moments through your code that pointing all out is some work. I do use Qt 3D with Qt 5.12 and yes it takes steady hand and very safe C++ practices to create own 3D Geometry. Mind the example above: some fixed size buffer reserved for those `position` items and the it the buffer filled from vector `vertices` of unknown size. Better create some very strict helper to prevent any underflow/overflow. To me the problem is around those lines. – Alexander V Jun 06 '21 at 16:33
  • I'v add `if ((vertices.size() * 3) == (vertex_buf.size()/sizeof(float)))` checking but i see the same errrors. This is my first such complicated task with Qt so in general i just wanna find the way how to debug it. And when i wrote it i hoped that somebody have same types of errors in working with Qt3D. – Alexey Chicherin Jun 07 '21 at 14:02
  • Start with most primitive single thing to present and then add more and see. Always enforce the safety with such type of buffer access. Asserts etc. – Alexander V Jun 07 '21 at 18:29
  • Thanks for your feedback! As a result of many hours of trying to solve the problem, partial and complete rewriting of the code, I decided to compile everything in the 5.15.2 version of the Qt. And everything works here without any errors as expected! After all, the examples and manuals that I was guided by were written in Qt5! Maybe later when Qt6 will be LTS and with official docs and examples about I will return to it. – Alexey Chicherin Jun 08 '21 at 05:40
  • Nothing new if they screwed up Qt3D again. We are the commercial customer and talk to Qt Company about many issues like that. They offer workaround etc. – Alexander V Jun 08 '21 at 13:32

0 Answers0