Skip to content

Commit 301222e

Browse files
committed
Properly check for uninitialized texture in CopyTexture class.
Before rendering the first frame, there is no output texture present in a preset, so we can't copy anything and should just skip that step.
1 parent f94f99d commit 301222e

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/libprojectM/Renderer/CopyTexture.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ void CopyTexture::Draw(const std::shared_ptr<class Texture>& originalTexture, co
157157
void CopyTexture::Draw(const std::shared_ptr<class Texture>& originalTexture, Framebuffer& framebuffer, int framebufferIndex,
158158
bool flipVertical, bool flipHorizontal)
159159
{
160-
if (originalTexture == nullptr || framebuffer.GetColorAttachmentTexture(framebufferIndex, 0) == nullptr)
160+
if (originalTexture == nullptr
161+
|| originalTexture->Empty()
162+
|| framebuffer.GetColorAttachmentTexture(framebufferIndex, 0) == nullptr
163+
|| framebuffer.GetColorAttachmentTexture(framebufferIndex, 0)->Empty())
161164
{
162165
return;
163166
}

src/libprojectM/Renderer/Texture.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Texture::Texture(std::string name, const int width, const int height, const bool
1515
, m_format(GL_RGB)
1616
, m_type(GL_UNSIGNED_BYTE)
1717
{
18-
CreateEmptyTexture();
18+
CreateNewTexture();
1919
}
2020

2121
Texture::Texture(std::string name, int width, int height,
@@ -29,7 +29,7 @@ Texture::Texture(std::string name, int width, int height,
2929
, m_format(format)
3030
, m_type(type)
3131
{
32-
CreateEmptyTexture();
32+
CreateNewTexture();
3333
}
3434

3535
Texture::Texture(std::string name, const GLuint texID, const GLenum target,
@@ -99,7 +99,12 @@ auto Texture::IsUserTexture() const -> bool
9999
return m_isUserTexture;
100100
}
101101

102-
void Texture::CreateEmptyTexture()
102+
auto Texture::Empty() const -> bool
103+
{
104+
return m_textureId == 0;
105+
}
106+
107+
void Texture::CreateNewTexture()
103108
{
104109
glGenTextures(1, &m_textureId);
105110
glBindTexture(m_target, m_textureId);

src/libprojectM/Renderer/Texture.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,17 @@ class Texture
115115
*/
116116
auto IsUserTexture() const -> bool;
117117

118+
/**
119+
* @brief Returns true if the texture is empty/unallocated.
120+
* @return true if the texture is not yet allocated (e.g. the ID 0), false if the object contains a valid texture.
121+
*/
122+
auto Empty() const -> bool;
123+
118124
private:
119-
void CreateEmptyTexture();
125+
/**
126+
* @brief Creates a new, blank texture with the given size.
127+
*/
128+
void CreateNewTexture();
120129

121130
GLuint m_textureId{0}; //!< The OpenGL texture name/ID.
122131
GLenum m_target{GL_NONE}; //!< The OpenGL texture target, e.g. GL_TEXTURE_2D.

0 commit comments

Comments
 (0)