[Bug 280278] After switching sdl20 to cmake, an error occurs in vulkan operation. Failed to create SDL window.

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 14 Jul 2024 15:20:48 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280278

            Bug ID: 280278
           Summary: After switching sdl20 to cmake, an error occurs in
                    vulkan operation. Failed to create SDL window.
           Product: Ports & Packages
           Version: Latest
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: ports-bugs@FreeBSD.org
          Reporter: a.hasumoto@gmail.com

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;
}
------------------------------------------------

-- 
You are receiving this mail because:
You are the assignee for the bug.