-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on Location display toggle during template load #1893
Comments
So, I have all the necessary bits. Too bad that I don't know where to get debuginfo for the build artifacts, but still I made progress. AFAICT, the crash originates at map.cpp:1990. Lines 1979 to 1999 in ac4b084
|
Between template selection and template loading, this code leaves 10 ms for event processing, meant for user input and display updates. This is a potential gap for a race condition (like TOCTOU), e.g. when the function is invoked a second time while an event is already pending. The lambda called by singleShot is bound to the template object, i.e. when the template is deleted, Qt shall remove the scheduled call from the event loop, thus preventing the access of deleted templates. If this doesn't happen immediately, then it will break. |
I tried to simulate this behaviour on the desktop, but failed. I did the the following:
|
Extra note: with the current 10 ms gap for event processing, input events don't seemt to be handled as soon as expected. With 50 ms, I can toggle GPS display multiple times during template loading. |
Looks like I arrive at reproducing in Android Emulator. Still need to arrange a full debug environment. |
Still no good debugging on Android, but now also reproducible on desktop. A simple test file was not enough. I have the same GPX file app. 10 times below and 10 times above the map. |
The scheduled template loading event is bound to the lifetime of the template object, but the lambda captures a reference to the unique_ptr owning the template. The lifetime of the unique_ptr can end before the lifetime of the pointed-to object when ownership is transferred to another unique_ptr. Here, this is triggered when the the template container reallocates memory due to insertion. We can safely capture a raw pointer to the template instead. Fixes GH-1893 (crash on early location display toggle).
It turned out that the problem was the lifetime of unique_ptr in the template container, not the lifetime of the template. |
The scheduled template loading event is bound to the lifetime of the template object, but the lambda captures a reference to the unique_ptr owning the template. The lifetime of the unique_ptr can end before the lifetime of the pointed-to object when ownership is transferred to another unique_ptr. Here, this is triggered when the the template container reallocates memory due to insertion. We can safely capture a raw pointer to the template instead. Fixes GH-1893 (crash on early location display toggle).
How to replicate:
Originally posted by @ollesmaps in #1892 (comment)
Observed with
OpenOrienteering-Mapper-refs_pull_1738_merge_v20210207.1-Android-armeabi-v7a
test build.The backtrace is always as this:
Unfortunately, I've deleted the corresponding .apk from my storage, so cannot proceed with reliable analysis. I'm waiting for replication with an official build.
The text was updated successfully, but these errors were encountered: