Skip to content

Commit

Permalink
Prevent SDL_WaitEvent loop from running before wlserver has finished …
Browse files Browse the repository at this point in the history
…initializing

fixes issue #661
  • Loading branch information
sharkautarch committed Feb 28, 2024
1 parent 701393d commit 7e2bc21
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ namespace gamescope
public:
virtual ~IBackend() {}

virtual void latchWait() { return; }
virtual void releaseLatch() { return; } //currently only used by sdl

virtual bool Init() = 0;
virtual bool PostInit() = 0;
virtual std::span<const char *const> GetInstanceExtensions() const = 0;
Expand Down
12 changes: 7 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,21 +803,21 @@ int main(int argc, char **argv)
if ( !GetBackend() )
{
fprintf( stderr, "Failed to create backend.\n" );
return 1;
exit(1);
}

g_ForcedNV12ColorSpace = parse_colorspace_string( getenv( "GAMESCOPE_NV12_COLORSPACE" ) );

if ( !vulkan_init_formats() )
{
fprintf( stderr, "vulkan_init_formats failed\n" );
return 1;
exit(1);
}

if ( !vulkan_make_output() )
{
fprintf( stderr, "vulkan_make_output failed\n" );
return 1;
exit(1);
}

// Prevent our clients from connecting to the parent compositor
Expand Down Expand Up @@ -846,7 +846,7 @@ int main(int argc, char **argv)
if ( g_nNestedWidth != 0 )
{
fprintf( stderr, "Cannot specify -w without -h\n" );
return 1;
exit(1);
}
g_nNestedWidth = g_nOutputWidth;
g_nNestedHeight = g_nOutputHeight;
Expand All @@ -857,7 +857,9 @@ int main(int argc, char **argv)
if ( !wlserver_init() )
{
fprintf( stderr, "Failed to initialize wlserver\n" );
return 1;
exit(1);
} else {
GetBackend()->releaseLatch();
}

gamescope_xwayland_server_t *base_server = wlserver_get_xwayland_server(0);
Expand Down
15 changes: 15 additions & 0 deletions src/sdlwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ namespace gamescope
// IBackend
/////////////

virtual void latchWait() override;
virtual void releaseLatch() override;
virtual bool Init() override;
virtual bool PostInit() override;
virtual std::span<const char *const> GetInstanceExtensions() const override;
Expand Down Expand Up @@ -179,6 +181,7 @@ namespace gamescope
std::thread m_SDLThread;
std::atomic<SDLInitState> m_eSDLInit = { SDLInitState::SDLInit_Waiting };

std::atomic<bool> m_sdlLatch = {false};
std::atomic<bool> m_bApplicationGrabbed = { false };
std::atomic<bool> m_bApplicationVisible = { false };
std::atomic<std::shared_ptr<INestedHints::CursorInfo>> m_pApplicationCursor;
Expand Down Expand Up @@ -336,6 +339,17 @@ namespace gamescope
return true;
}

void CSDLBackend::releaseLatch()
{
m_sdlLatch = true;
m_sdlLatch.notify_one();
}

void CSDLBackend::latchWait()
{
m_sdlLatch.wait(false);
}

std::span<const char *const> CSDLBackend::GetInstanceExtensions() const
{
return std::span<const char *const>{ m_pszInstanceExtensions.begin(), m_pszInstanceExtensions.end() };
Expand Down Expand Up @@ -631,6 +645,7 @@ namespace gamescope

static uint32_t fake_timestamp = 0;

latchWait();
SDL_Event event;
while( SDL_WaitEvent( &event ) )
{
Expand Down

0 comments on commit 7e2bc21

Please sign in to comment.