Skip to content

SDL_ShowMessageBox fails with non-null parent in Wayland #14273

@ningit

Description

@ningit

The following example tries to create a window and then a child message box (i.e. a message box with that window as the window attribute in the SDL_MessageBoxData structure).

#include <SDL3/SDL.h>

int main() {
	SDL_Init(SDL_INIT_VIDEO);

	SDL_Window* window;
	SDL_Renderer* renderer;

	SDL_CreateWindowAndRenderer("A window", 400, 400, 0, &window, &renderer);
	SDL_RenderClear(renderer);
	SDL_RenderPresent(renderer);

	SDL_Delay(1000);

	SDL_MessageBoxButtonData buttons[] = {
		{.flags = 0, .buttonID = 0, .text = "Close"},
	};

	SDL_MessageBoxData data = {
		.flags = 0,
		.window = window,
		.title = "A message box",
		.message = "This only works if window is nullptr.",
		.numbuttons = 1,
		.buttons = buttons,
		.colorScheme = nullptr,
	};

	int result = -1;
	SDL_ShowMessageBox(&data, &result);

	SDL_DestroyWindow(window);
	SDL_Quit();

	return 0;
}

However, this does not work on Wayland. I have built the program above with g++ $(pkg-config --libs sdl3) main.cpp -fsanitize=address -o example. Its behavior depends on the SDL_VIDEODRIVER environment variable:

  • With ./example (no environment variable), no message box appears and the address sanitizer complains about a SEGV somewhere inside libSDL3.so. The result of SDL_GetCurrentVideoDriver is wayland.
    • If the window field of data is replaced by nullptr, the message box appears (far from the window) and there is no SEGV.
    • If -fsanitize=address is not used, there is no visible complain for the SEGV, but the message box still does not appear.
  • With SDL_VIDEODRIVER=wayland ./example, no message box appears, but there is apparently no SEGV. This is quite surprising, because wayland seems to be the default driver.
  • With SDL_VIDEODRIVER=x11 ./example, the message box is shown and everything works as expected.

I am using SDL 3.2.24 on ArchLinux.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions