QtConcurrent mapped crashes
-
@akshaybabloo Please show the stack trace.
And what about my other suggestion? -
Your stacktrace shows a VideoSequencer class or function but your code does not.
-
@Christian-Ehrlicher Sorry. What does that mean?
-
Your code and your stack imo trace to not match. Compile your app in debug mode and show the back trace again. There must be line numbers for your code in the stack trace, not just for Qt.
-
@Christian-Ehrlicher When I try to do that, I get -
This does not seem to be a "Debug" build. Setting breakpoints by file name and line number may fail.
and I am in a Debug profile -
@Christian-Ehrlicher I tried to change the build type to Debug and now I get error in build settings as (screenshot):
Debug initial parameters are:
-GNinja -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake -DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} -DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} -DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} -DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
-
@Christian-Ehrlicher Never mind. The issue was with Conan. I got it working now.
And here is the screenshot:
Also added a small change:
QImage ImageFormatter::scaled(const QImage &image) { if (image.isNull()){ qDebug()<<image; return image; } return image.scaled(100,100); }
-
Ok, better now.
And you're sure the QImage is not touched from outside in another thread? Please take a look what the other threads are doing while it crashes. Is imageData still valid during the lifetime of QtConcurrent::mapped()? -
@Christian-Ehrlicher As far as I know, no. I am doing this only after creating the list of ImageData. The getters has
[[nodiscard]]
attribute. I am also using OpenCV to read in the video files and converting them into frames, but this is flushed after getting the frames.The code can be found at https://github.com/akshaybabloo/VideoSequencer
-
data->appendFrame(QImage(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888));
Default problem not reading the QImage documentation...
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
-
@Christian-Ehrlicher I have no idea what that means 😅
-
Hi,
You create a QImage out of an OpenCV Mat object. The constructor you use for that explicitly does not copy the data from the Mat object. This is what the warning is all about. It is your job to ensure that the Mat object lifetime is longer than the one of of your QImage.
Or you should explicitly trigger a copy of the QImage object when adding it to your array.
What happens is that when you do your concurrent call is that Mat object that used went out of scope and thus the QImage internal structure is now pointing to invalid data.