Skip to content

Fix null pointer access and avoid nested allocations with QOpenGLTexture - #13043

Merged
JoergAtGithub merged 5 commits into
mixxxdj:2.4from
daschuer:gh1258_24
Apr 17, 2024
Merged

Fix null pointer access and avoid nested allocations with QOpenGLTexture#13043
JoergAtGithub merged 5 commits into
mixxxdj:2.4from
daschuer:gh1258_24

Conversation

@daschuer

@daschuer daschuer commented Apr 3, 2024

Copy link
Copy Markdown
Member

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

m0dB commented Apr 4, 2024

Copy link
Copy Markdown
Contributor

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;

@m0dB m0dB Apr 4, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

@daschuer daschuer Apr 5, 2024

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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
@daschuer
daschuer deleted the gh1258_24 branch April 24, 2025 05:47
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