From issue #24909: in a monolithic build, the console applications of the sockets sample fail to communicate: baseserver never receives anything from baseclient. The problem was found via the wxIPC tests for PR #24858 and is not specific to the sample: it affects any console application relying on the default event loop in a monolithic build. The same baseserver/baseclient failure is also mentioned in #25005.
A backtrace of the listening server shows that the console application is erroneously running a GUI event loop (gtk_main() under wxGTK).
Note that the assert also quoted in these reports,
../src/common/timercmn.cpp(58): assert "traits" failed in Init(): Can't create timer, is wxApp fully initialized?
is a separate problem (#24856, already fixed on master) and is not affected by this change.
wxConsoleAppTraits::CreateEventLoop() returns new wxEventLoop(), and the meaning of wxEventLoop is fixed by the preprocessor when the library is compiled (include/wx/evtloop.h):
wxUSE_GUI==0, wxEventLoop is #defined to wxConsoleEventLoop;wxUSE_GUI==1, wxEventLoop is a class deriving from wxGUIEventLoop.In multilib builds the base library is compiled with -DwxUSE_GUI=0, so the console traits create the right loop. In a monolithic build every file is compiled with wxUSE_GUI==1 from setup.h, so the same line hands a wxGUIEventLoop to wxAppConsole. This also explains the observation in the issue discussion that the console application appeared to be using GUI code: the traits themselves were the correct wxConsoleAppTraits, but the loop they created was not.
Return new wxConsoleEventLoop() explicitly from wxConsoleAppTraits::CreateEventLoop() in both src/unix/evtloopunix.cpp and src/msw/basemsw.cpp (which has the same latent problem). For multilib builds this is a no-op, as wxEventLoop already expands to wxConsoleEventLoop in these files; for monolithic builds it selects the correct loop. The unix file also covers macOS, where wxConsoleEventLoop derives from wxCFEventLoop.
A second commit adds EventLoop::CreateFromTraits to tests/events/evtlooptest.cpp, checking that the application traits create an event loop of the appropriate kind; as this file is compiled into both test binaries, the same test case covers both console and GUI applications. The test fails against the unfixed monolithic library and passes with the fix, which also makes the sockets sample round-trip work again on wxGTK.
https://github.com/wxWidgets/wxWidgets/pull/26686
(3 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.![]()