QtConcurrent mapped crashes
-
@jsulm I got an popup window that says -
Stopped in thread 13 by: Exception at 0x7ff97c36bdda, code: 0xc0000005: read access violation at: 0x1b39f8c42ba, flags=0x0 (first chance).
And the console shows:
onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(10) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(11) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(12) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(13) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(14) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(15) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(16) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(17) tid(14090) 80070490 Element not found. onecore\com\combase\winrt\error\restrictederror.cpp(965)\combase.dll!00007FFA219D387F: (caller: 00007FFA218EBF94) LogHr(18) tid(14090) 80070490 Element not found.
-
@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.