Unbehandelte Ausnahme: Zugriffsverletzung beim Lesen an Position



  • Hallo, ich bastel momentan an einer kleiner Gameengine mit Vulkan, um zum einen C++ besser zu beherrschen und zum anderen auch um die Graphic-API kennen zu lernen.
    Doch nun bin ich auf ein kleines Problem gestoßen. In Vulkan gibt es sog. Instanzen. Um eine Instanz zu erstellen, muss ich ein Struct Namens VkApplicationInfo mit div. Parametern füllen und schließlich noch ein weiteres Struct Namens VkInstanceCreateInfo. Bishierhin funktioniert auch noch alles fehlerfrei.
    Aber beim erstellen der Instanz erhalte ich ein Problem:

    vkCreateInstance(&instanceCreateInfo, nullptr, &instance);
    

    Doch der Fehler tritt hier noch nicht auf.. Wenn ich noch ein bisschen weiter programmiere, gibt es erst das Problem:
    Wenn ich die VkPipelineColorBlendStateCreateInfo erstelle:

    VkPipelineColorBlendStateCreateInfo colorBlendCreateInfo;
    colorBlendCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
    colorBlendCreateInfo.pNext = nullptr;
    colorBlendCreateInfo.flags = 0;
    colorBlendCreateInfo.logicOpEnable = VK_FALSE;
    colorBlendCreateInfo.logicOp = VK_LOGIC_OP_NO_OP;
    colorBlendCreateInfo.attachmentCount = 1;
    colorBlendCreateInfo.pAttachments = &colorBlendAttachment;
    colorBlendCreateInfo.blendConstants[0] = 0.0f;
    colorBlendCreateInfo.blendConstants[1] = 0.0f;
    colorBlendCreateInfo.blendConstants[2] = 0.0f;
    colorBlendCreateInfo.blendConstants[3] = 0.0f;
    

    Kommentiere ich diesen Schritt aus, so erhalte ich keinen Fehler. Vielleicht ist das hier etwas aus dem Kontext gerissen, deswegen hier einmal der komplette Code um Vulkan hochzufahren: Irritieren tut mich, dass der Code der den Fehler auslöst, erst deutlich später ausgeführt wird. Der Fehler, der auftritt ist eine Fehlermeldung die ich von Java her mit einer NullPointerException gleichsetzen würde: Ausnahme ausgelöst bei 0x00007FFB19BE6A66 (amdvlk64.dll) in Engine.exe: 0xC0000005 Zugriffsverletzung beim Lesen an Position 0x000000000000A.
    Wenn Variablen Global sind erstelle ich sie in der Header-Datei:

    VkInstance instance;
    VkPhysicalDevice physicalDevice;
    VkDevice device;
    GLFWwindow *window;
    VkSurfaceKHR surface;
    VkSwapchainKHR swapChain;
    VkImageView *imageViews;
    VkPipelineColorBlendStateCreateInfo colorBlendCreateInfo;
    VkShaderModule shaderModuleVert;
    VkShaderModule shaderModuleFrag;
    VkPipelineLayout pipelineLayout;
    

    Hat jemand ne Idee, womit der Fehler zusammenhängen kann und wie ich ihn behoben kriege? Hier hab ich nochmal die gesamte Methode um Vulkan zu starten, falls es hilft den Fehler zu finden.

    void GraphicEngine::startVulkan()
    {
    	//VkApplicationInfo create
    	VkApplicationInfo appInfo;
    	appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
    	appInfo.pNext = NULL;
    	appInfo.pApplicationName = "Universe Evolution";
    	appInfo.applicationVersion = VK_MAKE_VERSION(0, 0, 1);
    	appInfo.engineVersion = VK_MAKE_VERSION(0, 0, 1);
    	appInfo.apiVersion = VK_API_VERSION_1_0;
    
    	uint32_t amountOfLayers = 0;
    	VkResult result = vkEnumerateInstanceLayerProperties(&amountOfLayers, NULL);
    	if (result == VK_SUCCESS || result == VK_INCOMPLETE)
    	{
    		VkLayerProperties *layers = new VkLayerProperties[amountOfLayers];
    		result = vkEnumerateInstanceLayerProperties(&amountOfLayers, layers);
    		if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    		{
    			if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    			{
    				std::cerr << "Running out of Host-Memory!" << std::endl;
    				exit(-1);
    			}
    			else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    			{
    				std::cerr << "Running out of Device-Memory!" << std::endl;
    				exit(-1);
    			}
    		}
    
    		std::cout << "Amount of Layers: " << amountOfLayers << std::endl;
    		for (int i = 0; i < amountOfLayers; i++)
    		{
    			std::cout << std::endl;
    			std::cout << "Name: " << layers[i].layerName << std::endl;
    			std::cout << "Spec-Version: " << layers[i].specVersion << std::endl;
    			std::cout << "Impl-Version: " << layers[i].implementationVersion << std::endl;
    			std::cout << "Description: " << layers[i].description << std::endl;
    		}
    
    		uint32_t amountOfExtensions = 0;
    		result = vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtensions, NULL);
    		if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    		{
    			if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    			{
    				std::cerr << "Running out of Host-Memory!" << std::endl;
    				exit(-1);
    			}
    			else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    			{
    				std::cerr << "Running out of Device-Memory!" << std::endl;
    				exit(-1);
    			}
    			else if (result == VK_ERROR_LAYER_NOT_PRESENT)
    			{
    				std::cerr << "Layer is not persent (Layer '" << "NULL" << "')" << std::endl;
    				result = vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtensions, NULL);
    				if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    				{
    					if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    					{
    						std::cerr << "Running out of Host-Memory!" << std::endl;
    						exit(-1);
    					}
    					else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    					{
    						std::cerr << "Running out of Device-Memory!" << std::endl;
    						exit(-1);
    					}
    					else if (result == VK_ERROR_LAYER_NOT_PRESENT)
    					{
    						std::cerr << "Layer is not persent (Layer '" << "NULL" << "')" << std::endl;
    						exit(-2);
    					}
    				}
    			}
    		}
    		VkExtensionProperties *extensions = new VkExtensionProperties[amountOfExtensions];
    		result = vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtensions, extensions);
    		if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    		{
    			if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    			{
    				std::cerr << "Running out of Host-Memory!" << std::endl;
    				exit(-1);
    			}
    			else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    			{
    				std::cerr << "Running out of Device-Memory!" << std::endl;
    				exit(-1);
    			}
    			else if (result == VK_ERROR_LAYER_NOT_PRESENT)
    			{
    				std::cerr << "Layer is not persent (Layer '" << "NULL" << "')" << std::endl;
    				result = vkEnumerateInstanceExtensionProperties(NULL, &amountOfExtensions, NULL);
    				if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    				{
    					if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    					{
    						std::cerr << "Running out of Host-Memory!" << std::endl;
    						exit(-1);
    					}
    					else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    					{
    						std::cerr << "Running out of Device-Memory!" << std::endl;
    						exit(-1);
    					}
    					else if (result == VK_ERROR_LAYER_NOT_PRESENT)
    					{
    						std::cerr << "Layer is not persent (Layer '" << "NULL" << "')" << std::endl;
    						exit(-2);
    					}
    				}
    			}
    		}
    		std::cout << std::endl;
    		std::cout << "Amount of Extensions: " << amountOfExtensions << std::endl;
    		for (int i = 0; i < amountOfExtensions; i++)
    		{
    			std::cout << std::endl;
    			std::cout << "Name: " << extensions[i].extensionName << std::endl;
    			std::cout << "Spec-Version: " << extensions[i].specVersion << std::endl;
    		}
    
    #ifdef sdk
    		const std::vector<const char*> validationLayers = {
    			"VK_LAYER_LUNARG_standard_validation", 
    			"VK_LAYER_LUNARG_api_dump"
    
    		};
    #endif
    
    #ifndef sdk
    		const std::vector<const char*> validationLayers = {
    			"VK_LAYER_LUNARG_standard_validation"
    		};
    #endif 
    
    
    		uint32_t amountOfGLFWExtensions = 0;
    		auto glfwExtensions = glfwGetRequiredInstanceExtensions(&amountOfGLFWExtensions);
    		std::cout << "Amount of GLFW-Extension: " << amountOfExtensions << std::endl;
    
    		//VkInstanceCreateInfo create
    		VkInstanceCreateInfo instanceCreateInfo;
    		instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
    		instanceCreateInfo.pNext = nullptr;
    		instanceCreateInfo.flags = 0;
    		instanceCreateInfo.pApplicationInfo = &appInfo;
    		instanceCreateInfo.enabledLayerCount = validationLayers.size();
    		instanceCreateInfo.ppEnabledLayerNames = validationLayers.data();
    		instanceCreateInfo.enabledExtensionCount = amountOfGLFWExtensions;
    		instanceCreateInfo.ppEnabledExtensionNames = glfwExtensions;
    
    		//Vulkan Instance create
    		VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);
    		//Fehlerbehandlung
    		if (result != VK_SUCCESS)
    		{
    			if (result == VK_ERROR_OUT_OF_HOST_MEMORY || result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    			{
    				std::cerr << "Running out of Memory in Host or in Device!" << std::endl;
    				exit(-1);
    			}
    			else if (result == VK_ERROR_INITIALIZATION_FAILED)
    			{
    				std::cerr << "Initialization Of Vulkan-Instance failed" << std::endl;
    				startVulkan();
    				return;
    			}
    			else if (result == VK_ERROR_LAYER_NOT_PRESENT || result == VK_ERROR_EXTENSION_NOT_PRESENT)
    			{
    				std::cerr << "Layer or Extension for Vulkan is not persent!" << std::endl;
    				instanceCreateInfo.enabledLayerCount = 0;
    				instanceCreateInfo.ppEnabledLayerNames = NULL;
    				instanceCreateInfo.enabledExtensionCount = 0;
    				instanceCreateInfo.ppEnabledExtensionNames = NULL;
    			}
    			else if (result == VK_ERROR_INCOMPATIBLE_DRIVER)
    			{
    				std::cerr << "Incompatible Driver" << std::endl;
    				exit(0); //TODO: Evtl später OpenGL Renderer versuchen vor Shutdown
    			}
    		}
    
    		result = glfwCreateWindowSurface(instance, window, NULL, &surface);
    		if (result != VK_SUCCESS)
    		{
    			if (result == GLFW_NOT_INITIALIZED)
    			{
    				shutdownGLFW();
    				startGLFW();
    				result = glfwCreateWindowSurface(instance, window, NULL, &surface);
    			}
    			else if (result == VK_ERROR_EXTENSION_NOT_PRESENT)
    			{
    				std::cerr << "VULKAN Extension is not persent" << std::endl;
    				for (int i = 0; i < amountOfExtensions; i++)
    				{
    					std::cout << "- " << extensions[i].extensionName << std::endl;
    				}
    			}
    			else if (result == VK_ERROR_LAYER_NOT_PRESENT)
    			{
    				std::cerr << "VULKAN Layer is not persent" << std::endl;
    				exit(1);
    			}
    		}
    		delete[] layers;
    		delete[] extensions;
    
    		//get amount of gpus
    		uint32_t amountOfPhysicalDevices = 0;
    		vkEnumeratePhysicalDevices(instance, &amountOfPhysicalDevices, NULL);
    		std::cout << "Amount of Graphic Cards: " << amountOfPhysicalDevices << std::endl;
    		//listing all physical devices
    		if (amountOfPhysicalDevices > 0)
    		{
    			VkPhysicalDevice * physicalDevices = new VkPhysicalDevice[amountOfPhysicalDevices];
    			vkEnumeratePhysicalDevices(instance, &amountOfPhysicalDevices, physicalDevices);
    			physicalDevice = physicalDevices[0];
    			//Possibility to get Features of PhysicalDevice
    
    			uint32_t amountOfQueueFamilies = 0;
    			vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &amountOfQueueFamilies, NULL);
    			VkQueueFamilyProperties* queueFamilyProperties = new VkQueueFamilyProperties[amountOfQueueFamilies];
    			vkGetPhysicalDeviceQueueFamilyProperties(physicalDevice, &amountOfQueueFamilies, queueFamilyProperties);
    			//Properties of QueueFamilies:
    			std::cout << "Amount of Queue Families: " << amountOfQueueFamilies << std::endl;
    			for (int i = 0; i < amountOfQueueFamilies; i++)
    			{
    				std::cout << std::endl;
    				std::cout << "Queue-Familiy #" << i << std::endl;
    				std::cout << "VK_QUEUE_GRAPHICS_BIT " << ((queueFamilyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)) << std::endl;
    				std::cout << "VK_QUEUE_COMPUTE_BIT " << ((queueFamilyProperties[i].queueFlags & VK_QUEUE_COMPUTE_BIT)) << std::endl;
    				std::cout << "VK_QUEUE_TRANSFER_BIT " << ((queueFamilyProperties[i].queueFlags & VK_QUEUE_TRANSFER_BIT)) << std::endl;
    				std::cout << "VK_QUEUE_SPARS_BINDING_BIT " << ((queueFamilyProperties[i].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) << std::endl;
    				std::cout << "Amount Of Queues: " << queueFamilyProperties[i].queueCount << std::endl;
    				std::cout << "Timestamp Valid Bits: " << queueFamilyProperties[i].timestampValidBits << std::endl;
    				std::cout << "Min Image TimeStamp Granularity: " << queueFamilyProperties[i].minImageTransferGranularity.width << "," << queueFamilyProperties[i].minImageTransferGranularity.height << "," << queueFamilyProperties[i].minImageTransferGranularity.depth << std::endl;
    			}
    
    			VkSurfaceCapabilitiesKHR surfaceCapabilities;
    			vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &surfaceCapabilities);
    			std::cout << "Surface capabilities: " << std::endl;
    			std::cout << "\tminImageCount:           " << surfaceCapabilities.minImageCount << std::endl;
    			std::cout << "\tmaxImageCount:           " << surfaceCapabilities.maxImageCount << std::endl;
    			std::cout << "\tcurrentExtent:           " << surfaceCapabilities.currentExtent.width << "/" << surfaceCapabilities.currentExtent.height << std::endl;
    			std::cout << "\tminImageExtent:          " << surfaceCapabilities.minImageExtent.width << "/" << surfaceCapabilities.minImageExtent.height << std::endl;
    			std::cout << "\tmaxImageExtent:          " << surfaceCapabilities.maxImageExtent.width << "/" << surfaceCapabilities.minImageExtent.height << std::endl;
    			std::cout << "\tmaxImageArrayLayers:     " << surfaceCapabilities.maxImageArrayLayers << std::endl;
    			std::cout << "\tsupportedTransforms:     " << surfaceCapabilities.supportedTransforms << std::endl;
    			std::cout << "\tcurrentTransform:        " << surfaceCapabilities.currentTransform << std::endl;
    			std::cout << "\tsupportedCompositeAlpha: " << surfaceCapabilities.supportedCompositeAlpha << std::endl;
    			std::cout << "\tsupportedUsageFlags:     " << surfaceCapabilities.supportedUsageFlags << std::endl;
    
    			uint32_t amountOfFormats = 0;
    			result = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &amountOfFormats, nullptr);
    			if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_SURFACE_LOST_KHR)
    				{
    					std::cout << "Surface is lost. Creating new Surface.." << std::endl; //todo: Creating new Surface
    				}
    			}
    			VkSurfaceFormatKHR *surfaceFormats = new VkSurfaceFormatKHR[amountOfFormats];
    			result = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, &amountOfFormats, surfaceFormats);
    			if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_SURFACE_LOST_KHR)
    				{
    					std::cout << "Surface is lost. Creating new Surface.." << std::endl; //todo: Creating new Surface
    				}
    			}
    
    			std::cout << std::endl;
    			std::cout << "Amount of Formats: " << amountOfFormats << std::endl;
    			for (int i = 0; i < amountOfFormats; i++)
    			{
    				std::cout << "Formats: " << surfaceFormats[i].format << std::endl;
    			}
    
    			uint32_t amountOfPresentationModes = 0;
    			result = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, &amountOfPresentationModes, nullptr);
    			if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_SURFACE_LOST_KHR)
    				{
    					std::cout << "Surface is lost. Creating new Surface.." << std::endl; //todo: Creating new Surface
    				}
    			}
    			VkPresentModeKHR * presentModes = new VkPresentModeKHR[amountOfPresentationModes];
    			result = vkGetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, &amountOfPresentationModes, presentModes);
    			if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_SURFACE_LOST_KHR)
    				{
    					std::cout << "Surface is lost. Creating new Surface.." << std::endl; //todo: Creating new Surface
    				}
    			}
    
    			//SwapchainCreateInfo
    
    
    			std::cout << std::endl;
    			std::cout << "Amount of Presentation Modes: " << amountOfPresentationModes << std::endl;
    			for (int i = 0; i < amountOfPresentationModes; i++)
    			{
    				std::cout << "Supported presentation mode: " << presentModes[i] << std::endl;
    			}
    
    			const float queuePrios[] = { 1.0f };
    
    			VkDeviceQueueCreateInfo deviceQueueCreateInfo;
    			deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
    			deviceQueueCreateInfo.pNext = NULL;
    			deviceQueueCreateInfo.flags = 0;
    			deviceQueueCreateInfo.queueFamilyIndex = 0;	//TODO Pick best QueueFamilyIndex for my application -> What is best?
    			int amountOfQueues = 1;
    			if (queueFamilyProperties[0].queueCount >= amountOfQueues)
    			{
    				deviceQueueCreateInfo.queueCount = amountOfQueues;
    			}
    			else
    			{
    				deviceQueueCreateInfo.queueCount = queueFamilyProperties[0].queueCount;
    			}
    			deviceQueueCreateInfo.pQueuePriorities = queuePrios;
    
    			VkPhysicalDeviceFeatures usedFeatures = {};
    
    			const std::vector<const char*> deviceExtensions = {
    				VK_KHR_SWAPCHAIN_EXTENSION_NAME
    			};
    
    			VkDeviceCreateInfo deviceCreateInfo;
    			deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
    			deviceCreateInfo.pNext = NULL;
    			deviceCreateInfo.flags = 0;
    			deviceCreateInfo.queueCreateInfoCount = 1;
    			deviceCreateInfo.pQueueCreateInfos = &deviceQueueCreateInfo;
    			deviceCreateInfo.enabledLayerCount = 0;
    			deviceCreateInfo.ppEnabledLayerNames = NULL;
    			deviceCreateInfo.enabledExtensionCount = deviceExtensions.size();
    			deviceCreateInfo.ppEnabledExtensionNames = deviceExtensions.data();
    			deviceCreateInfo.pEnabledFeatures = &usedFeatures;
    
    
    			VkResult result = vkCreateDevice(physicalDevice, &deviceCreateInfo, NULL, &device); //TODO pick best device
    			if (result != VK_SUCCESS)
    			{
    				std::cerr << "Vulkan-Mistake at Creating logical Device" << std::endl;
    			}
    
    			VkQueue queue;
    			vkGetDeviceQueue(device, 0, 0, &queue);
    
    			VkBool32 surfaceSupport = false;
    			result = vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, 0, surface, &surfaceSupport);
    			if (result != VK_SUCCESS)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_SURFACE_LOST_KHR)
    				{
    					std::cout << "Surface is lost. Creating new Surface.." << std::endl; //todo: Creating new Surface
    				}
    			}
    
    			if (!surfaceSupport)
    			{
    				std::cerr << "Surface not supported!" << std::endl;
    				exit(-1);
    			}
    
    			// Swapchain muss jedes mal neu erstellt werden wenn Größe des Bildschirms verändert wird
    			VkSwapchainCreateInfoKHR swapChainCreateInfo;
    			swapChainCreateInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    			swapChainCreateInfo.pNext = nullptr;
    			swapChainCreateInfo.flags = 0;
    			swapChainCreateInfo.surface = surface;
    
    			if (surfaceCapabilities.minImageCount >= 3)
    			{
    				swapChainCreateInfo.minImageCount = 3;
    			}
    			else
    			{
    				swapChainCreateInfo.minImageCount = surfaceCapabilities.minImageCount;
    			}
    
    			if (isImageFormatSupported(amountOfFormats, surfaceFormats, VK_FORMAT_B8G8R8A8_UNORM))
    			{
    				swapChainCreateInfo.imageFormat = VK_FORMAT_B8G8R8A8_UNORM;
    			}
    
    			swapChainCreateInfo.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; //todo civ
    			swapChainCreateInfo.imageExtent = VkExtent2D{WIDTH, HEIGHT};
    			swapChainCreateInfo.imageArrayLayers = 1;
    			swapChainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
    			swapChainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; //todo civ
    			swapChainCreateInfo.queueFamilyIndexCount = 0;
    			swapChainCreateInfo.pQueueFamilyIndices = nullptr;
    			swapChainCreateInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
    			swapChainCreateInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
    			swapChainCreateInfo.presentMode = VK_PRESENT_MODE_FIFO_KHR; //todo mail versuchen
    			swapChainCreateInfo.clipped = VK_TRUE;
    			swapChainCreateInfo.oldSwapchain = VK_NULL_HANDLE;
    
    			result = vkCreateSwapchainKHR(device, &swapChainCreateInfo, nullptr, &swapChain);
    			if (result != VK_SUCCESS)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_SURFACE_LOST_KHR)
    				{
    					std::cout << "Surface is lost. Creating new Surface.." << std::endl; //todo: Creating new Surface
    				}
    				else if (result == VK_ERROR_DEVICE_LOST)
    				{
    					std::cerr << "Device is lost. Please restart the Game!" << std::endl;
    				}
    				else if (result == VK_ERROR_NATIVE_WINDOW_IN_USE_KHR)
    				{
    					std::cerr << "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR" << std::endl;
    				}
    				else if (result == VK_ERROR_INITIALIZATION_FAILED)
    				{
    					std::cerr << "VK_ERROR_INITIALIZATION_FAILED" << std::endl;
    				}
    			}
    
    			
    			result = vkGetSwapchainImagesKHR(device, swapChain, &amountOfImagesInSwapChain, nullptr);
    			if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    			}
    			VkImage *swapchainImages = new VkImage[amountOfImagesInSwapChain];
    			result = vkGetSwapchainImagesKHR(device, swapChain, &amountOfImagesInSwapChain, swapchainImages);
    			if (result != VK_SUCCESS && result != VK_INCOMPLETE)
    			{
    				if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    				{
    					std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    					exit(-1);
    				}
    				else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    				{
    					std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    					exit(-1);
    				}
    			}
    
    			imageViews = new VkImageView[amountOfImagesInSwapChain];
    			for (int i = 0; i < amountOfImagesInSwapChain; i++)
    			{
    				//VkImageViewCreateInfo
    				VkImageViewCreateInfo imageViewCreateInfo;
    				imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
    				imageViewCreateInfo.pNext = nullptr;
    				imageViewCreateInfo.flags = 0;
    				imageViewCreateInfo.image = swapchainImages[i];
    				imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
    				if (isImageFormatSupported(amountOfFormats, surfaceFormats, VK_FORMAT_B8G8R8A8_UNORM))
    					imageViewCreateInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
    				imageViewCreateInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
    				imageViewCreateInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
    				imageViewCreateInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
    				imageViewCreateInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
    				imageViewCreateInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
    				imageViewCreateInfo.subresourceRange.baseMipLevel = 0;
    				imageViewCreateInfo.subresourceRange.levelCount = 1;
    				imageViewCreateInfo.subresourceRange.baseArrayLayer = 0;
    				imageViewCreateInfo.subresourceRange.layerCount = 1;
    
    				result = vkCreateImageView(device, &imageViewCreateInfo, nullptr, &imageViews[i]);
    				if (result != VK_SUCCESS)
    				{
    					if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    					{
    						std::cerr << "Programm running out of Host Memory. Please allocate more Host-Memory to Game!" << std::endl;
    						exit(-1);
    					}
    					else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    					{
    						std::cerr << "Programm running out of Device Memory. Please allocate more Device-Memory to Game" << std::endl;
    						exit(-1);
    					}
    				}
    			}
    			//Shader-Loading
    
    			std::vector<char> shaderCodeVert = readFile("vert.spv");
    			std::vector<char> shaderCodeFrag = readFile("frag.spv");
    
    			createShaderModule(shaderCodeVert, &shaderModuleVert);
    			createShaderModule(shaderCodeFrag, &shaderModuleFrag);
    
    			VkPipelineShaderStageCreateInfo shaderStageCreateInfoVert;
    			VkPipelineShaderStageCreateInfo shaderStageCreateInfoFrag;
    			createPipeLineShaderStageCreateInfoVert(shaderModuleVert, shaderStageCreateInfoVert);
    			createPipeLineShaderStageCreateInfoVert(shaderModuleFrag, shaderStageCreateInfoFrag);
    			VkPipelineShaderStageCreateInfo shaderStages[] = { shaderStageCreateInfoVert, shaderStageCreateInfoFrag };
    
    			//Feste Bestandteile Pipline initialisieren
    			
    			VkPipelineVertexInputStateCreateInfo vertexInputCreateInfo;
    			vertexInputCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
    			vertexInputCreateInfo.pNext = nullptr;
    			vertexInputCreateInfo.flags = 0;
    			vertexInputCreateInfo.vertexBindingDescriptionCount = 0;
    			vertexInputCreateInfo.pVertexBindingDescriptions = nullptr;
    			vertexInputCreateInfo.vertexAttributeDescriptionCount = 0;
    			vertexInputCreateInfo.pVertexAttributeDescriptions = nullptr;
    
    			VkPipelineInputAssemblyStateCreateInfo inputAssemblyCreateInfo;
    			inputAssemblyCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
    			inputAssemblyCreateInfo.pNext = nullptr;
    			inputAssemblyCreateInfo.flags = 0;
    			inputAssemblyCreateInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
    			inputAssemblyCreateInfo.primitiveRestartEnable = VK_FALSE;
    
    			VkViewport viewport;
    			viewport.x = 0.0f;
    			viewport.y = 0.0f;
    			viewport.width = WIDTH;
    			viewport.height = HEIGHT;
    			viewport.minDepth = 0.0f;
    			viewport.maxDepth = 1.0f;
    			
    			VkRect2D scissor;
    			scissor.offset = { 0,0 };
    			scissor.extent = { WIDTH, HEIGHT };
    
    			VkPipelineViewportStateCreateInfo viewportStateCreateInfo;
    			viewportStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
    			viewportStateCreateInfo.pNext = nullptr;
    			viewportStateCreateInfo.flags = 0;
    			viewportStateCreateInfo.viewportCount = 1;
    			viewportStateCreateInfo.pViewports = &viewport;
    			viewportStateCreateInfo.scissorCount = 1;
    			viewportStateCreateInfo.pScissors = &scissor;
    
    			VkPipelineRasterizationStateCreateInfo rasterizationStateCreateInfo;
    			rasterizationStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
    			rasterizationStateCreateInfo.pNext = nullptr;
    			rasterizationStateCreateInfo.flags = 0;
    			rasterizationStateCreateInfo.depthClampEnable = VK_FALSE;
    			rasterizationStateCreateInfo.rasterizerDiscardEnable = VK_FALSE;
    			rasterizationStateCreateInfo.polygonMode = VK_POLYGON_MODE_FILL;
    			rasterizationStateCreateInfo.cullMode = VK_CULL_MODE_BACK_BIT;
    			rasterizationStateCreateInfo.frontFace = VK_FRONT_FACE_CLOCKWISE;
    			rasterizationStateCreateInfo.depthBiasEnable = VK_FALSE;
    			rasterizationStateCreateInfo.depthBiasConstantFactor = 0.0f;
    			rasterizationStateCreateInfo.depthBiasClamp = 0.0f;
    			rasterizationStateCreateInfo.depthBiasSlopeFactor = 0.0f;
    			rasterizationStateCreateInfo.lineWidth = 1.0f;
    
    			
    			VkPipelineMultisampleStateCreateInfo multisampleStateCreateInfo;
    			multisampleStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
    			multisampleStateCreateInfo.pNext = nullptr;
    			multisampleStateCreateInfo.flags = 0;
    			multisampleStateCreateInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
    			multisampleStateCreateInfo.sampleShadingEnable = VK_FALSE;
    			multisampleStateCreateInfo.minSampleShading = 1.0f;
    			multisampleStateCreateInfo.pSampleMask = nullptr;
    			multisampleStateCreateInfo.alphaToCoverageEnable = VK_FALSE;
    			multisampleStateCreateInfo.alphaToOneEnable = VK_FALSE;
    			 
    			VkPipelineColorBlendAttachmentState colorBlendAttachment;
    			colorBlendAttachment.blendEnable = VK_TRUE;
    			colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
    			colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
    			colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
    			colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
    			colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
    			colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
    			colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT & VK_COLOR_COMPONENT_G_BIT & VK_COLOR_COMPONENT_B_BIT & VK_COLOR_COMPONENT_A_BIT;
    
    		
    			VkPipelineColorBlendStateCreateInfo colorBlendCreateInfo;
    			colorBlendCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
    			colorBlendCreateInfo.pNext = nullptr;
    			colorBlendCreateInfo.flags = 0;
    			colorBlendCreateInfo.logicOpEnable = VK_FALSE;
    			colorBlendCreateInfo.logicOp = VK_LOGIC_OP_NO_OP;
    			colorBlendCreateInfo.attachmentCount = 1;
    			colorBlendCreateInfo.pAttachments = &colorBlendAttachment;
    			colorBlendCreateInfo.blendConstants[0] = 0.0f;
    			colorBlendCreateInfo.blendConstants[1] = 0.0f;
    			colorBlendCreateInfo.blendConstants[2] = 0.0f;
    			colorBlendCreateInfo.blendConstants[3] = 0.0f;
    
    			delete[] physicalDevices;
    			delete[] queueFamilyProperties;
    			delete[] surfaceFormats;
    			delete[] presentModes;
    		}
    	}
    	else if (result == VK_ERROR_OUT_OF_HOST_MEMORY)
    	{
    		std::cerr << "Running out of Host-Memory!" << std::endl;
    		exit(-1);
    	}
    	else if (result == VK_ERROR_OUT_OF_DEVICE_MEMORY)
    	{
    		std::cerr << "Running out of Device-Memory!" << std::endl;
    		exit(-1);
    	}
    }
    


  • In welcher Zeile wird der Fehler ausgelöst?

    @Fawkes sagte in Unbehandelte Ausnahme: Zugriffsverletzung beim Lesen an Position:

    Hier hab ich nochmal die gesamte Methode um Vulkan zu starten, falls es hilft den Fehler zu finden.

    lol



  • @hustbaer Der Fehler wird beim erstellen der Instanz ausgelöst, also bei

    VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);
    

    Wenn ich im späteren Verlauf allerdings die

    VkPipelineColorBlendStateCreateInfo colorBlendCreateInfo;
    

    weglasse, gibt es keinen Fehler.


Anmelden zum Antworten