英文:
SDL2 failing to initialize on Crostini ChromeOS
问题
I am running on a Debian 10 Bullseye Crostini VM on ChromeOS 111.0.5563.100. Here is my SDL2 code...
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main(int argc, char *argv[])
{
bool rungame = true;
if (!SDL_Init(SDL_INIT_VIDEO))
{
perror("Failed to initialize SDL");
return -1;
}
SDL_Window *window = SDL_CreateWindow(
"Dungeoneer",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCR_W,
SCR_H,
SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI
);
if (window == NULL)
{
perror("SDL Window failed to initialize");
return 1;
}
SDL_Renderer *render = SDL_CreateRenderer(
window,
-1,
SDL_RENDERER_ACCELERATED
);
if (render is NULL)
{
perror("SDL Renderer failed to initialize");
return 2;
}
SDL_Event event;
while (rungame)
{
SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
SDL_RenderClear(render);
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
return 0;
break;
}
}
SDL_RenderPresent(render);
}
return 0;
}
I am not getting any compilation errors or warnings. But when I execute the returned binary file that I receive with this command...
g++ main.cpp -o main.out -Wall -lm -lSDL2
I get this result...
Failed to initialize SDL: Resource temporarily unavailable
What is interesting is that PyGame runs without any issue at all. I tried searching for any solution but I couldn't find anyone who has experienced a similar issue that I could derive a viable solution from.
英文:
I am running on a Debian 10 Bullseye Crostini VM on ChromeOS 111.0.5563.100. Here is my SDL2 code...
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main(int argc, char *argv[])
{
bool rungame = true;
if (!SDL_Init(SDL_INIT_VIDEO))
{
perror("Failed to initialize SDL");
return -1;
}
SDL_Window *window = SDL_CreateWindow(
"Dungeoneer",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SCR_W,
SCR_H,
SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI
);
if (window == NULL)
{
perror("SDL Window failed to initialize");
return 1;
}
SDL_Renderer *render = SDL_CreateRenderer(
window,
-1,
SDL_RENDERER_ACCELERATED
);
if (render == NULL)
{
perror("SDL Renderer failed to initialize");
return 2;
}
SDL_Event event;
while (rungame)
{
SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
SDL_RenderClear(render);
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
return 0;
break;
}
}
SDL_RenderPresent(render);
}
return 0;
}
I am not getting any compilation errors or warnings. But when I execute the returned binary file that I receive with this command...
g++ main.cpp -o main.out -Wall -lm -lSDL2
I get this result...
Failed to initialize SDL: Resource temporarily unavailable
What is interesting is that PyGame runs without any issue at all. I tried searching for any solution but I couldn't find anyone who has experienced a similar issue that I could derive a viable solution from.
答案1
得分: 0
我找到了解决方案。
sudo apt install xorg-dev
根据我找到的信息,SDL2需要这个库才能进行开发。Crostini使用x11窗口服务器来运行Linux GUI应用程序,所以需要安装开发包。
英文:
After some more research, I found the solution.
sudo apt install xorg-dev
From what I found, SDL2 requires this library in order to be developed. Crostini uses a x11 window server to run Linux GUI applications, so this makes sense that you would need the development package.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论