Bug 280278 - After switching devel/sdl20 to cmake, an error occurs in vulkan operation. Failed to create SDL window.
Summary: After switching devel/sdl20 to cmake, an error occurs in vulkan operation. Fa...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Dmitry Marakasov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-14 15:20 UTC by Atsushi Hasumoto
Modified: 2024-07-25 11:38 UTC (History)
2 users (show)

See Also:
linimon: maintainer-feedback? (amdmi3)


Attachments
patch (2.12 KB, patch)
2024-07-24 19:33 UTC, Dmitry Marakasov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Atsushi Hasumoto 2024-07-14 15:20:48 UTC
When I checked the operation of the test program created with chatgpt using sdl2 and vulkan, the following error occurred.

error ---------------------------------------
Failed to create SDL window.

source code ---------------------------------
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#include <vulkan/vulkan.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
#include <vector>

const int WIDTH = 800;
const int HEIGHT = 600;

class VulkanApp {
public:
    void run() {
        initWindow();
        initVulkan();
        mainLoop();
        cleanup();
    }

private:
    SDL_Window* window;
    VkInstance instance;

    void initWindow() {
        if (SDL_Init(SDL_INIT_VIDEO) != 0) {
            throw std::runtime_error("Failed to initialize SDL.");
        }

        window = SDL_CreateWindow("Vulkan Triangle",
                                  SDL_WINDOWPOS_CENTERED,
                                  SDL_WINDOWPOS_CENTERED,
                                  WIDTH,
                                  HEIGHT,
                                  SDL_WINDOW_VULKAN);

        if (!window) {
            throw std::runtime_error("Failed to create SDL window.");
        }
    }

    void initVulkan() {
        createInstance();
        // ここでさらに必要な初期化を行います
    }

    void createInstance() {
        VkApplicationInfo appInfo{};
        appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
        appInfo.pApplicationName = "Vulkan Triangle";
        appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
        appInfo.pEngineName = "No Engine";
        appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
        appInfo.apiVersion = VK_API_VERSION_1_0;

        VkInstanceCreateInfo createInfo{};
        createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
        createInfo.pApplicationInfo = &appInfo;

        if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
            throw std::runtime_error("Failed to create Vulkan instance.");
        }
    }

    void mainLoop() {
        bool quit = false;
        SDL_Event event;
        while (!quit) {
            while (SDL_PollEvent(&event)) {
                if (event.type == SDL_QUIT) {
                    quit = true;
                }
            }
        }
    }

    void cleanup() {
        vkDestroyInstance(instance, nullptr);
        SDL_DestroyWindow(window);
        SDL_Quit();
    }
};

int main() {
    VulkanApp app;

    try {
        app.run();
    } catch (const std::exception& e) {
        std::cerr << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
------------------------------------------------
Comment 1 Dmitry Marakasov freebsd_committer freebsd_triage 2024-07-24 19:33:33 UTC
Created attachment 252262 [details]
patch

Could you please try this patch?
Comment 2 Atsushi Hasumoto 2024-07-25 03:55:28 UTC
Thank you for providing the patch.
With this migration to cmake, I tried to see if I could solve the problem myself, but I started relying on you.
I'll try this patch when I have time.
In the future, I would like to improve my skills and be able to cooperate and contribute to everyone.
Comment 3 Atsushi Hasumoto 2024-07-25 07:49:20 UTC
Hello, Dmitry..
Thank you for providing this patch.
After applying this patch and checking the operation, we were able to confirm that the operation had returned to normal.

I will also show you the results of the ldd command....
atsushi@localhost:~/work/program/vulkan/projects/test % ldd ./test 
./test:
        libSDL2-2.0.so.0 => /usr/local/lib/libSDL2-2.0.so.0 (0x1a97b313a000)
        libvulkan.so.1 => /usr/local/lib/libvulkan.so.1 (0x1a97b35d4000)
        libc++.so.1 => /lib/libc++.so.1 (0x1a97b4c7c000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x1a97b41ed000)
        libm.so.5 => /lib/libm.so.5 (0x1a97b588b000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x1a97b5d27000)
        libc.so.7 => /lib/libc.so.7 (0x1a97b6b9a000)
        libX11.so.6 => /usr/local/lib/libX11.so.6 (0x1a97b8312000)
        libXext.so.6 => /usr/local/lib/libXext.so.6 (0x1a97b7dc6000)
        libXcursor.so.1 => /usr/local/lib/libXcursor.so.1 (0x1a97b8e70000)
        libXi.so.6 => /usr/local/lib/libXi.so.6 (0x1a97b98ee000)
        libXfixes.so.3 => /usr/local/lib/libXfixes.so.3 (0x1a97b9e99000)
        libXrandr.so.2 => /usr/local/lib/libXrandr.so.2 (0x1a97ba80b000)
        libXss.so.1 => /usr/local/lib/libXss.so.1 (0x1a97babaa000)
        libdrm.so.2 => /usr/local/lib/libdrm.so.2 (0x1a97bbab6000)
        libgbm.so.1 => /usr/local/lib/libgbm.so.1 (0x1a97bcf25000)
        libEGL.so.1 => /usr/local/lib/libEGL.so.1 (0x1a97bbd29000)
        libwayland-egl.so.1 => /usr/local/lib/libwayland-egl.so.1 (0x1a97bc4a2000)
        libwayland-client.so.0 => /usr/local/lib/libwayland-client.so.0 (0x1a97bcf79000)
        libwayland-cursor.so.0 => /usr/local/lib/libwayland-cursor.so.0 (0x1a97be7bd000)
        libxkbcommon.so.0 => /usr/local/lib/libxkbcommon.so.0 (0x1a97bd151000)
        libinotify.so.0 => /usr/local/lib/libinotify.so.0 (0x1a97bdcac000)
        libusbhid.so.4 => /usr/lib/libusbhid.so.4 (0x1a97bf6cc000)
        libthr.so.3 => /lib/libthr.so.3 (0x1a97bf90f000)
        libxcb.so.1 => /usr/local/lib/libxcb.so.1 (0x1a97c06b4000)
        libXrender.so.1 => /usr/local/lib/libXrender.so.1 (0x1a97c0e1c000)
        libwayland-server.so.0 => /usr/local/lib/libwayland-server.so.0 (0x1a97c1c12000)
        libexpat.so.1 => /usr/local/lib/libexpat.so.1 (0x1a97c201d000)
        libGLdispatch.so.0 => /usr/local/lib/libGLdispatch.so.0 (0x1a97c2ee4000)
        libdl.so.1 => /usr/lib/libdl.so.1 (0x1a97c439a000)
        libepoll-shim.so.0 => /usr/local/lib/libepoll-shim.so.0 (0x1a97c3376000)
        libffi.so.8 => /usr/local/lib/libffi.so.8 (0x1a97c3b4b000)
        libXau.so.6 => /usr/local/lib/libXau.so.6 (0x1a97c4d6c000)
        libXdmcp.so.6 => /usr/local/lib/libXdmcp.so.6 (0x1a97c63c5000)
        [vdso] (0x1a97b2610000)
Comment 4 commit-hook freebsd_committer freebsd_triage 2024-07-25 11:38:23 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=43c1ea15875dbc5dbc386269b6a0747295741457

commit 43c1ea15875dbc5dbc386269b6a0747295741457
Author:     Dmitry Marakasov <amdmi3@FreeBSD.org>
AuthorDate: 2024-07-25 11:36:40 +0000
Commit:     Dmitry Marakasov <amdmi3@FreeBSD.org>
CommitDate: 2024-07-25 11:37:10 +0000

    devel/sdl20: fix vulkan support

    PR:             280278
    Reported by:    a.hasumoto@gmail.com

 devel/sdl20/Makefile                   |  1 +
 devel/sdl20/files/patch-CMakeLists.txt | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
Comment 5 Dmitry Marakasov freebsd_committer freebsd_triage 2024-07-25 11:38:44 UTC
Thanks! I was able to confirm the fix too. Committed.

Also, upstream PR: https://github.com/libsdl-org/SDL/pull/10361