-
Notifications
You must be signed in to change notification settings - Fork 26
fix: try to fix crash in processWaylandEvents #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |||||
| #include <QAbstractEventDispatcher> | ||||||
| #include <QSocketNotifier> | ||||||
| #include <QMutex> | ||||||
| #include <QDebug> | ||||||
| #include <QLoggingCategory> | ||||||
| #include <QProcess> | ||||||
| #include <QLocalServer> | ||||||
| #include <QLocalSocket> | ||||||
|
|
@@ -38,6 +38,8 @@ | |||||
| QW_USE_NAMESPACE | ||||||
| WAYLIB_SERVER_BEGIN_NAMESPACE | ||||||
|
|
||||||
| Q_LOGGING_CATEGORY(qLcWlrServer, "waylib.server.core") | ||||||
|
|
||||||
| static bool globalFilter(const wl_client *client, | ||||||
| const wl_global *global, | ||||||
| void *data) { | ||||||
|
|
@@ -102,20 +104,20 @@ void WServerPrivate::init() | |||||
| } | ||||||
|
|
||||||
| loop = wl_display_get_event_loop(display->handle()); | ||||||
| int fd = wl_event_loop_get_fd(loop); | ||||||
|
|
||||||
| auto processWaylandEvents = [this] { | ||||||
| int ret = wl_event_loop_dispatch(loop, 0); | ||||||
| if (ret) | ||||||
| fprintf(stderr, "wl_event_loop_dispatch error: %d\n", ret); | ||||||
| wl_display_flush_clients(display->handle()); | ||||||
| }; | ||||||
| const int fd = wl_event_loop_get_fd(loop); | ||||||
| if (fd == -1) { | ||||||
| qCFatal(qLcWlrServer) << "Did not get the file descriptor for the event loop"; | ||||||
| } | ||||||
|
|
||||||
| sockNot.reset(new QSocketNotifier(fd, QSocketNotifier::Read)); | ||||||
| QObject::connect(sockNot.get(), &QSocketNotifier::activated, q, processWaylandEvents); | ||||||
| QObject::connect(sockNot.get(), &QSocketNotifier::activated, q, [this] { | ||||||
| dispatchEvents(); | ||||||
| }); | ||||||
|
|
||||||
| QAbstractEventDispatcher *dispatcher = QThread::currentThread()->eventDispatcher(); | ||||||
| QObject::connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, q, processWaylandEvents); | ||||||
| QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher(); | ||||||
| QObject::connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, q, [this] { | ||||||
| flush(); | ||||||
| }); | ||||||
|
|
||||||
| for (auto socket : std::as_const(sockets)) | ||||||
| initSocket(socket); | ||||||
|
|
@@ -142,6 +144,18 @@ void WServerPrivate::stop() | |||||
| QThread::currentThread()->eventDispatcher()->disconnect(q); | ||||||
| } | ||||||
|
|
||||||
| void WServerPrivate::dispatchEvents() | ||||||
| { | ||||||
| int ret = wl_event_loop_dispatch(loop, 0); | ||||||
| if (ret) | ||||||
| qCCritical(qLcWlrServer, "wl_event_loop_dispatch error: %d\n", ret); | ||||||
|
||||||
| qCCritical(qLcWlrServer, "wl_event_loop_dispatch error: %d\n", ret); | |
| qCCritical(qLcWlrServer, "wl_event_loop_dispatch error: %d", ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent event dispatcher retrieval in the stop() method. The init() method was changed to use QCoreApplication::eventDispatcher() (line 117), but stop() still uses QThread::currentThread()->eventDispatcher(). These should be consistent to avoid potential issues if the event dispatcher changes or if the server is accessed from different threads.