Skip to content
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

Fix crash disabling quantize #11744

Merged
merged 3 commits into from Jul 18, 2023
Merged

Fix crash disabling quantize #11744

merged 3 commits into from Jul 18, 2023

Conversation

daschuer
Copy link
Member

Make m_marksToRender a std::map to have a constant sort key.

This fixes the crash due to changing sort keys reported in #11709

@ywwg
Copy link
Member

ywwg commented Jul 15, 2023

I'll set this up with my js spammer just to confirm the fix :)

Copy link
Contributor

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a std::map here might be convenient but is the wrong choice for this use case.

src/waveform/renderers/waveformmark.h Show resolved Hide resolved
src/waveform/renderers/waveformmark.h Show resolved Hide resolved
@daschuer
Copy link
Member Author

@uklotzde, your review is pretty useless if you don't explain you opinion and don't add a proposal for improvements.

@uklotzde
Copy link
Contributor

uklotzde commented Jul 16, 2023

A map is used for dynamically adding and removing elements. In this case the keys are stable, but become inconsistent at the time when they are created. You will not be able to remove an element reliably by its key once it has been inserted. This only gets worse while time passes.

Using a map is deceiving. A developer will easily create a key from a WaveformMarkPointer and try to use it for accessing the map. Using a map makes it easy to make this and other mistakes.

@uklotzde
Copy link
Contributor

I am done with my "useless" review.

@ywwg
Copy link
Member

ywwg commented Jul 16, 2023

I see the point, that usually the key in a map is an accessor, and that the sample position is not really a useful way to access the items in this map. However this code is isolated and this hack is pretty self-contained. It is unlikely that this choice will cause large problems down the line, and if this turns out to be an inconvenient solution we can leave enough comments to explain why this choice was made. I think this is fine for now to fix the severe party-crashing bug.

We are always open to specific alternative approaches to fixing issues. I think ideally the solution would involve a dirty flag and snapshotting cue data at render time in a thread-safe way to render their data. Most likely all this code will disappear when the QML rewrite is done, so I'm not sure it's worth doing a 100%-correct-and-pretty solution here.

@daschuer daschuer changed the base branch from 2.4 to 2.3 July 16, 2023 22:15
@daschuer
Copy link
Member Author

Thank you for review. I have rebased this to 2.3. because the 2.3 branch is also affected form the crasher.

@uklotzde
Copy link
Contributor

so I'm not sure it's worth doing a 100%-correct-and-pretty solution here.

Please note that I deliberately did not request "a 100%-correct-and-pretty solution"! I only pointed out that the current design and code (which includes comments) is prone to introducing new bugs.

@JoergAtGithub
Copy link
Member

The text of the commit message seems to be accidentally here

This fixes the crash due to changing sort keys reported in mixxxdj#11709
@daschuer
Copy link
Member Author

Oh, yes. I must have messed up the rebase to 2.3. Now the old message is back.

@ywwg
Copy link
Member

ywwg commented Jul 17, 2023

Please note that I deliberately did not request "a 100%-correct-and-pretty solution"! I only pointed out that the current design and code (which includes comments) is prone to introducing new bugs.

I appreciate the review, truly. I think this solution is at least incrementally better than the current proven-dangerous code. Would you be opposed to merging as-is, or is it sufficient that we have raised the issue and are aware of the possible downsides?

@uklotzde
Copy link
Contributor

All downsides should be documented, i.e. "Don't consider this map as a regular map! It is rebuilt periodically only for the purpose of sorting entries.".

That's the bare minimum, software engineering 101.

@uklotzde
Copy link
Contributor

It is the duty of the PR owner to choose a suitable option to resolve the questions and concerns that have been expressed. I didn't exclude any of them.

@daschuer
Copy link
Member Author

This this is still a regular map and I cannot confirm your concerns. The issue for me is that your complains are kind of common, not specific to this use case of this private container. I have considered different solutions and this is IMHO the best best we can pick in terms of performance and architecture. But maybe I am wrong, you can prove it by providing a different solution.
For now I will tweak the comments a bit and than I am done.

Comment on lines 94 to 96
// This class stores the data used as a sorting key immutable.
// We cannot use the the mark directly, because it can be
// altered at any time.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This class stores the data used as a sorting key immutable.
// We cannot use the the mark directly, because it can be
// altered at any time.
// This class provides an immutable sortkey for the WaveformMark using sample position and hotcue enum. IMPORTANT: the Mark's position may be changed after a key's creation, and those updates will not be reflected in these sortkeys. Therefore these keys should not be retained for long periods of time. Currently they are used to render marks on the Overview, a situation where temporarily incorrect mark position is acceptable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Feel free to copy and paste to fix newlines, etc)

@daschuer
Copy link
Member Author

Done.

@daschuer daschuer added this to the 2.3.6 milestone Jul 18, 2023
@ywwg ywwg merged commit 66b768f into mixxxdj:2.3 Jul 18, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants