SDL: SDL2 opens no window without giving any errors on VMWare
I’m trying to test a simple SDL2 application. The app runs without any errors. However, no window shows up.
I’m using Ubuntu18.04 on a VMWare machine. I also tried to compile SDL from the source but got the same result. The problem might be related to using the virtual machine.
Here is a simple application from docs (I just added SDL_GetNumDisplayModes to make sure the display mode is OK- returns 1)
The version is 2.28, and I’ve already enabled 3D graphics on my VM.
// Using SDL and standard IO
#include <SDL2/SDL.h>
#include <stdio.h>
// Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char *args[])
{
// The window we'll be rendering to
SDL_Window *window = NULL;
// The surface contained by the window
SDL_Surface *screenSurface = NULL;
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
}
else
{
int res = SDL_GetNumDisplayModes(0);
printf("SDL_GetNumDisplayModes: %d\r\n", res);
// Create window
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if (window == NULL)
{
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
}
else
{
// Get window surface
screenSurface = SDL_GetWindowSurface(window);
// Fill the surface white
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));
// Update the surface
SDL_UpdateWindowSurface(window);
// Hack to get window to stay up
SDL_Event e;
bool quit = false;
while (quit == false)
{
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
quit = true;
}
}
}
}
}
// Destroy window
SDL_DestroyWindow(window);
// Quit SDL subsystems
SDL_Quit();
return 0;
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (9 by maintainers)
Ah, I see now. Ubuntu 18.04 ships libwayland 1.16, while SDL wants 1.18 at minimum, so that’s why it’s failing.
Wayland has other dependencies as well:
libxkbcommon-devandlibegl1-mesa-dev. I see EGL support in that log, so the latter is there, is xkbcommon installed?This is probably the issue then as @icculus mentioned:
checking for Wayland support... noUbuntu 18.04 should default to Wayland, you can confirm with
echo $XDG_SESSION_TYPE.I think it’s the package
libwayland-devyou need. You can check if it’s installed withdpkg -l | grep libwayland-devand install it withsudo apt install libwayland-devEdit: As a clarification as to why you didn’t get any errors I’m guessing is because SDL chose the offscreen renderer as your default. So your window is rendering but inside a buffer and never actually to a real display. I’m not very knowledgeable with this particular renderer.
Oh. I didn’t realize this was locally built. I thought it was the lib that ships in apt.
Can you attach the output of configure or cmake so we can see what happened during configuration?
I’m no expert in VMWare. Since nothing is obviously breaking you’ll have to investigate further and see if you can figure out what the issue could be I guess. Perhaps your window doesn’t get any dimensions etc.
If you run this code you should get some more info: