SDL2 在 Crostini ChromeOS 上初始化失败

huangapple go评论58阅读模式
英文:

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 &lt;SDL2/SDL.h&gt;

int main(int argc, char *argv[])
{
    bool rungame = true;

    if (!SDL_Init(SDL_INIT_VIDEO))
    {
        perror(&quot;Failed to initialize SDL&quot;);
        return -1;
    }
    
    SDL_Window *window = SDL_CreateWindow(
        &quot;Dungeoneer&quot;,
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        SCR_W,
        SCR_H,
        SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI
    );
    if (window == NULL)
    {
        perror(&quot;SDL Window failed to initialize&quot;);
        return 1;
    }

    SDL_Renderer *render = SDL_CreateRenderer(
        window,
        -1,
        SDL_RENDERER_ACCELERATED
    );
    if (render == NULL)
    {
        perror(&quot;SDL Renderer failed to initialize&quot;);
        return 2;
    }

    SDL_Event event;
    while (rungame)
    {
        SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
        SDL_RenderClear(render);
        
        while (SDL_PollEvent(&amp;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.

huangapple
  • 本文由 发表于 2023年3月31日 02:51:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75891963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定