Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multithreading conversion of QModelIndexList to treeItem crash

Multithreading conversion of QModelIndexList to treeItem crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewqmodelindexqmodelindexlist
4 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on last edited by aha_1980
    #1

    Hey

    I'm working on optimizing some of my functions, I recently come across an unusual bug.

    Here is roughly the function:;

    listPrimay = selectedIndexes()/// simplified, this is just a list of column 0 indexes after filtering in larger app, just dropped selecttedIndexes() for simplicity here. 
    #pragma omp parallel for
        for (int x = 0; x < listPrimary.size(); ++x) {
            mNodeListSelected[x] = *static_cast< std::shared_ptr<myTreeNode> * >(listPrimary[x].internalPointer());
        }
    

    Now if I run this app, and I do shift+select, it all goes well. But if I do a lot of quick selections 1 after another. Then I get a crash with following crash debug log :

    testApp.exe!QTypedArrayData<QModelIndex>::deallocate(QArrayData * data) Line 238	C++
    testApp.exe!QVector<QModelIndex>::freeData(QTypedArrayData<QModelIndex> * x) Line 543	C++
    testApp.exe!QVector<QModelIndex>::reallocData(const int asize, const int aalloc, QFlags<enum QArrayData::AllocationOption> options) Line 639	C++
    testApp.exe!QVector<QModelIndex>::detach() Line 391	C++
    testApp.exe!QVector<QModelIndex>::data() Line 127	C++
    testApp.exe!QVector<QModelIndex>::operator[](int i) Line 437	C++
    testApp.exe!myTree::notifyOfNewSelection$omp$1() Line 774	C++
    

    (1st call - being last call)

        static void deallocate(QArrayData *data)
        {
            Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData));
            QArrayData::deallocate(data, sizeof(T), Q_ALIGNOF(AlignmentDummy));
        }
    
    FATAL: ASSERT failure in QArrayData::deallocate: "Static data can not be deleted", file tools\qarraydata.cpp, line 166
     (tools\qarraydata.cpp:166, (null))
    

    What should I do? I'm lost, and I could really use multithreading conversion from 1 type item to another.

    Seems to be like Qt might be invalidating/deleting the indexes between selections while the loop converts them to items and since qt does it in different thread I lose them? Or hmmm ? No idea what to do here. I tried using mutex/static mutext but no luck.

    Regards
    Dariusz
    TIA

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      Don't use multithreading here at all - just using multithreading to do a static case is useless.

      /edit: and your threading problem exists because you're writing to a container from different thread without synchronizing the access with e.g. a mutex

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • D Offline
        D Offline
        Dariusz
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thanks for info.
        "Don't use multithreading here at all - just using multithreading to do a static case is useless."
        Well I have 100k items +/- to deal with. Doing it on 1 core feels somewhat slow I think...

        "/edit: and your threading problem exists because you're writing to a container from different thread without synchronizing the access with e.g. a mutex"
        I created the base vectors via QVector<myTreeNode> vec(vecSize) and I access them all via [], so no thread should step over another thread, There should be no need for mutex here I think?

        Regards
        Dariusz

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Dariusz said in Multithreading conversion of QModelIdnexList to treeItem crash:

          Well I have 100k items +/- to deal with

          Then you should avoid to dereference the pointers to not copy the data around.

          I created the base vectors via QVector<myTreeNode> vec(vecSize) and I access them all via [], so no thread should step over another thread,

          It does as your backtrace shows. Since you're using QVector which is implicit shared every write access to the container checks if the container needs to get detached. Maybe try with a non-implicit shared container instead (e.g. a std::vector)
          See http://doc.qt.io/qt-5/implicit-sharing.html for details.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved