I've been trying to solve this problem and I've been drawing a blank. Below is the script I have been trying to run with no success. All that happens for me is I run the program, the script initializes SDL3, loads the default library, creates a window, then queries the necessary extensions. Upon running SDL_Vulkan_GetInstanceExtensions(...)
, I get the error "Invalid Window" from SDL_GetError()
. I'm creating the window with SDL_WINDOW_VULKAN
, but it's not working. I've debugged and the window is not NULL
, it does appear on the screen. However, I can't do anything to fix this. Leaving the header files I'm using in because I don't know if that might be interfering with the process.
#include <stdlib.h>
#include <stdio.h>
#include <vulkan/vulkan.h>
#include <cglm/cglm.h>
#include <vk_mem_alloc.h>
#include <time.h>
#define SDL_MAIN_HANDLED
#include <SDL3/SDL.h>
#include <SDL3/SDL_vulkan.h>
typedef struct Window_T {
SDL_Window* window;
VkExtent2D size;
char* name;
VkSurfaceKHR surface;
} Window;
int main(void) {
printf("Hello, World!\n");
SDL_Init(SDL_INIT_VIDEO);
printf("ERROR INIT: %s\n", SDL_GetError());
SDL_Vulkan_LoadLibrary(NULL);
printf("ERROR LOAD: %s\n", SDL_GetError());
Window window;
//createWindow(&window, 800, 600, "Hello from SDL3");
window.window = SDL_CreateWindow("Hello, SDL3!", 800, 600, SDL_WINDOW_VULKAN);
printf("ERROR MAKE: %s\n", SDL_GetError());
Uint32 sdl_required_extension_count;
const char* const* sdl_required_extensions = SDL_Vulkan_GetInstanceExtensions(&sdl_required_extension_count);
printf("SDL_REQUIRED_EXTENSION_COUNT: %d\n", sdl_required_extension_count);
printf("ERROR: %s\n", SDL_GetError());
SDL_DestroyWindow(window.window);
return 0;
}
I've tried printf
debugging, SDL_GetError()
, checking the linker, reading the documentation, but nothing seems to be showing the solution. If anyone can help I would be very grateful!
I've tried to replicate your code using SDL preview-3.1.6 and both the extension number and the required extensions get reported correctly. The steps I followed are:
git clone https://github.com/libsdl-org/SDL.git SDL
SDL/VisualC/SDL.sln
SDL/include
.SDL/VisualC/x64/Debug
SDL/VisualC/x64/Debug/SDL3.dll
into the same folder as the exe.If after following these steps you get the same error you need to check that you have a good Vulkan installation and that you are linking correctly with SDL.
First thing I would try is to check that the demos in the Vulkan SDK work. You can find them at %VULKAN_SDK%/Demos
.
After that I would test a basic triangle sample you can find online. For example:
git clone --recursive https://github.com/SaschaWillems/Vulkan.git
cmake -G "Visual Studio 16 2019" -A x64
If the Vulkan Demos or the Triangle Example work it means you have a problem with SDL. Check that you are linking with the correct lib/dll or try with SDL2.
To make tesing easier you can use this batch file:
@echo off
setlocal enabledelayedexpansion
:compile
set prjName=Sandbox
set files=%~dp0\src\main.cpp
set buildDir=%~dp0\build\Win-x64-%target%\%prjName%\
set buildIntDir=%~dp0\build-int\Win-x64-%target%\%prjName%\
set exceptions=-EHa-
set subsystem=-subsystem:console
echo Building %prjName% for %target%...
set compilerFlags=^
-Fe%prjName% ^
-Fo%buildIntDir% ^
-diagnostics:column ^
-Oi -Gm- -GR- %exceptions% -FC -nologo -std:c++17 ^
-fp:fast -fp:except- ^
-D_HAS_EXCEPTIONS=0 ^
-I %~dp0\src ^
-I%VULKAN_SDK%\Include ^
-IC:\dev\SDL\include
set debugCompilerFlags=-MDd -Zo -Zi
set releaseCompilerFlags=-MD -GL -O2
set linkerFlags=-WX -opt:ref -incremental:no %subsystem% -LIBPATH:C:\dev\SDL\VisualC\x64\Debug
:: Create Build directories and copy resources.res
if not exist %buildDir% mkdir %buildDir%
if not exist %buildIntDir% mkdir %buildIntDir%
pushd %buildDir%
del %prjName%.pdb > NUL 2> NUL
del %prjName%.* > NUL 2> NUL
cl %compilerFlags% %debugCompilerFlags% %files% /link %linkerFlags% SDL3.lib
popd
goto :exit
:exit
exit /B !ERRORLEVEL!
With this folder structure:
- build.bat
- [src]
- main.cpp
- [build]
- [build-int]
Call build.bat
and the copy SDL/VisualC/x64/Debug/SDL3.dll
in build/Win-x64-Debug/Sandbox
. Afther that you can open the exe in Visual Studio or your debugger of choice and test it.