Skip to content

Commit 91f8d93

Browse files
committed
test
1 parent 427cbf2 commit 91f8d93

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

rpcs3/rpcs3qt/camera_settings_dialog.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,12 @@ void camera_settings_dialog::handle_sdl_settings_change(const QVariant& item_dat
630630
{
631631
// It was observed that connecting sendVideoFrame directly can soft-lock the software.
632632
// So let's just create the video frame here and call it manually.
633-
const QVideoFrame video_frame(m_sdl_image);
634-
m_video_frame_input->sendVideoFrame(video_frame);
633+
std::unique_lock lock(m_sdl_image_mutex, std::defer_lock);
634+
if (lock.try_lock())
635+
{
636+
const QVideoFrame video_frame(m_sdl_image);
637+
m_video_frame_input->sendVideoFrame(video_frame);
638+
}
635639
});
636640
#endif
637641

@@ -674,18 +678,20 @@ void camera_settings_dialog::run_sdl()
674678
}
675679

676680
#if (QT_VERSION_MAJOR >= 6 && QT_VERSION_MINOR >= 8) // TODO: Remove when MacOs is at Qt 6.8+
677-
Emu.BlockingCallFromMainThread([this, frame]()
678681
{
679682
// Map image
680683
const QImage::Format format = SDL_ISPIXELFORMAT_ALPHA(frame->format) ? QImage::Format_RGBA8888 : QImage::Format_RGB888;
681684
const QImage image = QImage(reinterpret_cast<const u8*>(frame->pixels), frame->w, frame->h, format);
682685

683686
// Copy image to prevent memory access violations
684-
m_sdl_image = image.copy();
687+
{
688+
std::lock_guard lock(m_sdl_image_mutex);
689+
m_sdl_image = image.copy();
690+
}
685691

686692
// Notify UI
687693
Q_EMIT sdl_frame_ready();
688-
});
694+
}
689695
#endif
690696

691697
SDL_ReleaseCameraFrame(m_sdl_camera, frame);

rpcs3/rpcs3qt/camera_settings_dialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#endif
1212
#include <QVideoFrame>
1313

14+
#include <mutex>
15+
1416
#ifdef HAVE_SDL3
1517
#ifndef _MSC_VER
1618
#pragma GCC diagnostic push
@@ -62,6 +64,7 @@ private Q_SLOTS:
6264
SDL_Camera* m_sdl_camera = nullptr;
6365
SDL_CameraID m_sdl_camera_id = 0;
6466
QImage m_sdl_image;
67+
std::mutex m_sdl_image_mutex;
6568
std::unique_ptr<named_thread<std::function<void()>>> m_sdl_thread;
6669
#if (QT_VERSION_MAJOR >= 6 && QT_VERSION_MINOR >= 8) // TODO: Remove when MacOs is at Qt 6.8+
6770
std::unique_ptr<QVideoFrameInput> m_video_frame_input;

0 commit comments

Comments
 (0)