all repos — mgba @ 4807d684825af75f16b19cd03a4dbbd6520f4a60

mGBA Game Boy Advance Emulator

Qt: Attempt to fix DisplayGL crash
Vicki Pfau vi@endrift.com
Fri, 31 Jul 2020 01:33:47 -0700
commit

4807d684825af75f16b19cd03a4dbbd6520f4a60

parent

8a9a8859a68b8abdc2632cfe9dcf3b91a281f685

1 files changed, 7 insertions(+), 12 deletions(-)

jump to
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -487,8 +487,6 @@ float r = m_surface->devicePixelRatio();

m_backend->resized(m_backend, m_size.width() * r, m_size.height() * r); if (m_buffer) { m_backend->postFrame(m_backend, m_buffer); - m_free.append(m_buffer); - m_buffer = nullptr; } m_backend->drawFrame(m_backend); m_painter.endNativePainting();

@@ -498,7 +496,7 @@ }

} void PainterGL::enqueue(const uint32_t* backing) { - m_mutex.lock(); + QMutexLocker locker(&m_mutex); uint32_t* buffer = nullptr; if (backing) { if (m_free.isEmpty()) {

@@ -506,17 +504,17 @@ buffer = m_queue.dequeue();

} else { buffer = m_free.takeLast(); } - QSize size = m_context->screenDimensions(); - memcpy(buffer, backing, size.width() * size.height() * BYTES_PER_PIXEL); + if (buffer) { + QSize size = m_context->screenDimensions(); + memcpy(buffer, backing, size.width() * size.height() * BYTES_PER_PIXEL); + } } m_queue.enqueue(buffer); - m_mutex.unlock(); } void PainterGL::dequeue() { - m_mutex.lock(); + QMutexLocker locker(&m_mutex); if (m_queue.isEmpty()) { - m_mutex.unlock(); return; } uint32_t* buffer = m_queue.dequeue();

@@ -524,10 +522,7 @@ if (m_buffer) {

m_free.append(m_buffer); m_buffer = nullptr; } - if (buffer) { - m_buffer = buffer; - } - m_mutex.unlock(); + m_buffer = buffer; } void PainterGL::dequeueAll() {