-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
GlobalTrackCache: Fix edge cases and tests #2293
Conversation
...to avoid that more track objects are created than destroyed.
Next try, functors need to be copyable. |
I was not able to find out which test actually caused the crash and had to add a workaround. The WPushButtonTest can't be the culprit. Startup and shutdown of application components during tests don't seem to be sane. |
The crash during the tests is hopefully fixed now. The insights gained from this analysis and the resulting fix might also eliminate the rare crashes on shutdown. Only time will tell. |
src/track/globaltrackcache.cpp
Outdated
DEBUG_ASSERT(plainPtr->signalsBlocked()); | ||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0) | ||
if (plainPtr->thread()->loopLevel() > 0) { | ||
plainPtr->deleteLater(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://doc.qt.io/qt-5/qthread.html:
Note: This can only be called within the thread itself, i.e. when it is the current thread.
Is this guaranteed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Cache entries are always evicted on the main (event loop) thread, and then the track pointer goes out of scope. ...or maybe not. I need to check this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a correct, more explicit solution. The tests now provide a function pointer to override the default QObject::deleteLater()
deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new solution is independent of the Qt version.
In a branch without these changes the spurious crashes are back. Seems like the fixes work as expected! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes are looking sensible.
Unfortunately I do not understand which part is the crux for the crash fix here?
Can you give some additional hints.
src/track/globaltrackcache.h
Outdated
void operator()(Track* pTrack) const; | ||
|
||
private: | ||
deleteTrackFn m_deleteTrack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about deleteTrackFn m_deleteTrackFn
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_typeName
? The name of the function is deleteTrack
, the corresponding type is deleteTrackFn
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have stumbled over this because it can also be bool m_deleteTrack;
The idea was to make it obvious from the variable name that this is a function pointer.
src/track/globaltrackcache.cpp
Outdated
if (trackById != m_tracksById.end()) { | ||
DEBUG_ASSERT(trackById->second->getPlainPtr() == plainPtr); | ||
if (trackById != m_tracksById.end() && | ||
trackById->second->getPlainPtr() == plainPtr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if this fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to check this again
Possible crash fixes:
Not sure which of these actually fixed the issue. The tests never worked as intended and the issues slipped through unnoticed. |
LGTM, thank you. |
I still experience a crash caused by GlobalTrackCache once in a while when closing Mixxx. It happens very infrequently, mostly after loading just a single or a few tracks. These crashes may still be unsolved, nevertheless I discovered some other issues during my investigations: