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 null pointer access and avoid nested allocations with QOpenGLTexture #13043

Merged
merged 5 commits into from
Apr 17, 2024

Conversation

daschuer
Copy link
Member

@daschuer daschuer commented Apr 3, 2024

This adds a missing null check in ec4bf17 to fix #12580

During testing I have noticed that QOpenGLTexture itself is only a smart pointer to the texture storage. This can also potentially be null. So I refactored the code to avoid a second allocation to store a pointer to QOpenGLTexture.

The last commit is only refactoring. Can this also be integrated in 2.4 or should I split it out for main?

@m0dB
Copy link
Contributor

m0dB commented Apr 4, 2024

I don't see the problem with using a unique_ptr, but I do not oppose this change. It can be integrated in both 2.4 and main IMO. Thanks for taking care of this while I was away!

Approved with one request for a comment. I propose you merge it yourself, @daschuer, if you also want to take care of 2.4.

#include <QSharedPointer>

class Paintable;

Copy link
Contributor

@m0dB m0dB Apr 4, 2024

Choose a reason for hiding this comment

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

maybe add a comment that explains that this is an extension of QOpenGLTexture, with additional methods to set the texture data, and default settings for filter and wrap mode.

Comment on lines 15 to 14
std::unique_ptr<QOpenGLTexture> generateTexture(float markerLength,
void generateTexture(OpenGLTexture2D* pTexture,
Copy link
Member

Choose a reason for hiding this comment

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

I really don't see how the tradeoff in code quality makes sense. There is no reason to introduce an out-parameter here IMO. If the extra allocation bothers you, why not return it by value directly?

Copy link
Member Author

@daschuer daschuer Apr 5, 2024

Choose a reason for hiding this comment

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

This is this no out parameter which may be considered as bad code quality these days. It just updates the texture via pointer because OpenGLTexture2D has no copy constructor . I kept just to avoid moving code around. I will now make it a normal member function as usual and rename it to avoid future confusion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored to become drawPrerollImage() returning the temporary QImage.

@JoergAtGithub
Copy link
Member

I tested this on Windows 11 and it works stable. The review comment by Swiftb0y is addressed. Code LGTM! Thank you for taking care!

@JoergAtGithub JoergAtGithub merged commit 82d601c into mixxxdj:2.4 Apr 17, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants