Skip to content

Commit 7576f5b

Browse files
committed
Skin: Fix texture deallocation
1 parent 285aa88 commit 7576f5b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/skin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ Skin::Skin()
1212
QOpenGLContext *context = QOpenGLContext::currentContext();
1313
Q_ASSERT(context);
1414

15-
if (context) {
16-
QObject::connect(context, &QOpenGLContext::aboutToBeDestroyed, &m_signalHandler, [this]() {
15+
if (!m_destroyConnected && context) {
16+
QObject::connect(context, &QOpenGLContext::aboutToBeDestroyed, []() {
1717
// Destroy textures
1818
m_textures.clear();
1919
});
20+
21+
m_destroyConnected = true;
2022
}
2123
}
2224

src/skin.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Skin
2626
virtual void paint(QPainter *painter) = 0;
2727

2828
private:
29-
std::vector<std::shared_ptr<QOpenGLTexture>> m_textures;
30-
QObject m_signalHandler; // for disconnecting signals after destroyed
29+
static inline std::vector<std::shared_ptr<QOpenGLTexture>> m_textures;
30+
static inline bool m_destroyConnected = false;
3131
};
3232

3333
} // namespace scratchcpprender

0 commit comments

Comments
 (0)