-1

I am working on a Qt app which runs on android & iOS.

Scenario: Calling delete on a pointer causes my app to crash sometimes gives me the following error on Android.

Fatal signal 11 (SIGSEGV), code 1, fault addr 0x3c in tid 7134 (QtThread)

This is caused due to a delete call in updatePaintNode of my QQuickItem derived class.

// My updatePaintNode logic relevant to this question
QSGNode * MyQQuickItem::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) {

  Q_UNUSED(oldNode)
  Q_UNUSED(updatePaintNodeData)

  if(class_mem_node != Q_NULLPTR) {
    delete class_mem_node;    // this is where the crash occurs
  }

  class_mem_node = new QSGNode;

  // Execute drawing logic

  return class_mem_node;
}

Problem:
Another window of my application is dependent on MyQQuickItem::updatePaintNode to execute but sometimes on Android the call to delete class_mem_node causes the crash with the Fatal signal error. Interestingly, the issue only happens on android, not on iOS or OSX.

Question:
What is wrong in my logic in updatePaintNode ? Is this a thread synchronisation issue?

Is there some way I can check whether the QSGNode is in use & return out?

TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159

1 Answers1

0

When you return class_mem_node; you don't have ownership of the class_mem_node any more.

The implementation may delete the node when it becomes not useful. It then passes nullptr as oldNode on the next call to the updatePaintNode().

Don't store class_mem_node, use oldNode.

Velkan
  • 7,067
  • 6
  • 43
  • 87