Skip to content

Commit 9f937b7

Browse files
committed
Add costume mutex
1 parent 302cd32 commit 9f937b7

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

ScratchCPPGui/renderedtarget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void RenderedTarget::loadCostume(Costume *costume)
8282
if (!costume)
8383
return;
8484

85+
m_costumeMutex.lock();
8586
Target *target = scratchTarget();
8687
m_costume = costume;
8788
m_imageChanged = true;
@@ -104,6 +105,8 @@ void RenderedTarget::loadCostume(Costume *costume)
104105
QSize size = reader.size();
105106
calculateSize(target, size.width(), size.height());
106107
}
108+
109+
m_costumeMutex.unlock();
107110
}
108111

109112
void RenderedTarget::updateProperties()
@@ -223,6 +226,16 @@ const QString &RenderedTarget::bitmapUniqueKey() const
223226
return m_bitmapUniqueKey;
224227
}
225228

229+
void RenderedTarget::lockCostume()
230+
{
231+
m_costumeMutex.lock();
232+
}
233+
234+
void RenderedTarget::unlockCostume()
235+
{
236+
m_costumeMutex.unlock();
237+
}
238+
226239
bool RenderedTarget::mirrorHorizontally() const
227240
{
228241
return m_mirrorHorizontally;

ScratchCPPGui/renderedtarget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class RenderedTarget : public QNanoQuickItem
5555
QBuffer *bitmapBuffer();
5656
const QString &bitmapUniqueKey() const;
5757

58+
void lockCostume();
59+
void unlockCostume();
60+
5861
bool mirrorHorizontally() const;
5962

6063
signals:
@@ -77,6 +80,7 @@ class RenderedTarget : public QNanoQuickItem
7780
unsigned char *m_svgBitmap = nullptr;
7881
QBuffer m_bitmapBuffer;
7982
QString m_bitmapUniqueKey;
83+
QMutex m_costumeMutex;
8084
QMutex mutex;
8185
bool m_imageChanged = false;
8286
bool m_visible = true;

ScratchCPPGui/targetpainter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TargetPainter::~TargetPainter()
1919

2020
void TargetPainter::paint(QNanoPainter *painter)
2121
{
22+
m_target->lockCostume();
2223
unsigned char *svgBitmap = m_target->svgBitmap();
2324
double width = m_target->width();
2425
double height = m_target->height();
@@ -43,6 +44,8 @@ void TargetPainter::paint(QNanoPainter *painter)
4344
QNanoImage image = QNanoImage::fromCache(painter, m_target->bitmapBuffer(), m_target->bitmapUniqueKey());
4445
painter->drawImage(image, 0, 0, width, height);
4546
}
47+
48+
m_target->unlockCostume();
4649
}
4750

4851
void TargetPainter::synchronize(QNanoQuickItem *item)

0 commit comments

Comments
 (0)