Adding more Window validation

This commit is contained in:
2026-04-06 14:28:58 +02:00
parent 7271fe8a0b
commit 87390db80d
4 changed files with 50 additions and 23 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
#include "MinimalEngine.h"
#include "RenderTarget.h"
#include "Resources.h"
#define ENABLE_VALIDATION
namespace Seele {
namespace Gfx {
+17 -2
View File
@@ -667,6 +667,17 @@ Array<const char*> Graphics::getRequiredExtensions() {
unsigned int glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
if (glfwExtensions == nullptr || glfwExtensionCount == 0) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::string message = "GLFW did not report required Vulkan instance extensions";
if (glfwError != nullptr) {
message += ": ";
message += glfwError;
}
throw std::runtime_error(message);
}
for (unsigned int i = 0; i < glfwExtensionCount; i++) {
extensions.add(glfwExtensions[i]);
}
@@ -677,8 +688,12 @@ Array<const char*> Graphics::getRequiredExtensions() {
}
void Graphics::initInstance(GraphicsInitializer initInfo) {
glfwInit();
assert(glfwVulkanSupported());
if (!glfwInit()) {
throw std::runtime_error("Failed to initialize GLFW");
}
if (!glfwVulkanSupported()) {
throw std::runtime_error("GLFW: Vulkan not supported");
}
VkApplicationInfo appInfo = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = nullptr,
+22 -1
View File
@@ -4,6 +4,7 @@
#include "Graphics.h"
#include "Resources.h"
#include <GLFW/glfw3.h>
#include <sstream>
using namespace Seele;
using namespace Seele::Vulkan;
@@ -61,6 +62,16 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* handle = glfwCreateWindow(createInfo.width / contentScaleX, createInfo.height / contentScaleY, createInfo.title, nullptr, nullptr);
if (handle == nullptr) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::string message = "Failed to create GLFW window";
if (glfwError != nullptr) {
message += ": ";
message += glfwError;
}
throw std::runtime_error(message);
}
windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
@@ -73,7 +84,17 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
// glfwSetWindowSizeCallback(handle, &glfwResizeCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
VkResult surfaceResult = glfwCreateWindowSurface(instance, handle, nullptr, &surface);
if (surfaceResult != VK_SUCCESS || surface == VK_NULL_HANDLE) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::ostringstream oss;
oss << "Failed to create Vulkan surface via GLFW (VkResult=" << surfaceResult << ")";
if (glfwError != nullptr) {
oss << ": " << glfwError;
}
throw std::runtime_error(oss.str());
}
querySurface();
chooseSwapSurfaceFormat();