Very Strange possible Bug

So basically I got the hello triangle intel tutorial working. My code has a number of differences with the official one because I didn’t compile the project but just kept copying bits and pieces of his code. So on line 250 right after I create a renderPass and right before I create a frameBuffer I found I had a redundant misnamed subresource range memory barrier variable and when I deleted it it caused my program to crash. It turned out not to be anything particular to to the vksubresource and when I replaced it with an array of 5 integers it worked again. So if you comment out or delete the array of ints on line 250 it crashes my program. So I think it’s a memory issue but it seems quite strange and I figured I would share it.

So I don’t like using windows visual studio. I use mingw, in particular Nuwen’s release and I compile it with:
g++ vulkan1.cpp -o vulkan1.exe -m64 -I C:\VulkanSDK\1.1.73.0\Include\vulkan -L C:\VulkanSDK\1.1.73.0\Lib -l vulkan-1 -lgdi32

Here is where the array that when deleted causes the crash is.

	if( vkCreateRenderPass( device, &renderPassInfo, nullptr, &renderPass ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to create renderpass. 
";
	}

	int asdf[5] = {1,2,3,4,5};

	
	/* create Framebuffer */
	std::vector<VkFramebuffer> frameBuffers;
	frameBuffers.resize(swapchainImages.size());	
	vkGetSwapchainImagesKHR( device, swapchain, &imageCount, &swapchainImages[0]);
#include <fstream>
#include <iostream>
#include <windows.h>
#include <vector>
#define VK_USE_PLATFORM_WIN32_KHR
#include <C:/VulkanSDK/1.1.73.0/Include/vulkan/vulkan.h>

/*
steps to compile:
1. download nuwen's mingw distro
2. download lunarg vulkan sdk
3. correct path names in the #include and also in the mingw command below as necessary and compile: 
g++ vulkan1.cpp -o vulkan1.exe -m64 -I C:\VulkanSDK\1.1.73.0\Include\vulkan -L C:\VulkanSDK\1.1.73.0\Lib -l vulkan-1 -lgdi32
if you delete the array on line 250 it causes it to crash
*/

/* win32 callback function to for the window */
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) 
	{
		case WM_DESTROY:
		{
			DestroyWindow(hWnd);
			PostQuitMessage(0);
		}
		break;
		default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	} 
}


INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	
	/* win32 initialization code */
	unsigned int windowWidth = 1280;
	unsigned int windowHeight = 720;
	HINSTANCE windowInstance;
	HWND window;
	const char * applicationName = "Triangle";
	AllocConsole();
	AttachConsole(GetCurrentProcessId());
	freopen("CON", "w", stdout);
	freopen("CON", "w", stderr);
	SetConsoleTitle(TEXT(applicationName));

	WNDCLASSEX windowInfo = 
	{
	sizeof(WNDCLASSEX),										//UINT      cbSize;
	CS_HREDRAW | CS_VREDRAW,						//UINT      style;
	WndProc,															//WNDPROC   lpfnWndProc;
	0,																		//int       cbClsExtra;
	0,																		//int       cbWndExtra;
	windowInstance,												//HINSTANCE hInstance;
	LoadIcon(NULL, IDI_APPLICATION),					//HICON     hIcon;
	LoadCursor(NULL, IDC_ARROW),						//HCURSOR   hCursor;
	(HBRUSH)GetStockObject(BLACK_BRUSH),		//HBRUSH    hbrBackground;
	NULL,																//LPCTSTR   lpszMenuName;
	applicationName,												//LPCTSTR   lpszClassName;
	LoadIcon(NULL, IDI_APPLICATION)					//HICON     hIconSm;
	};
	
	RegisterClassEx(&windowInfo);
	int windowFlags = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
	window = CreateWindowEx( 0, applicationName, applicationName, windowFlags, 0, 0, windowWidth+16, windowHeight+38, 0, 0, windowInstance, 0);
	ShowWindow(window, SW_SHOW);
	SetForegroundWindow(window);
	SetFocus(window);
	RECT win32Rect;
	GetClientRect(window, &win32Rect);
	
	/*Create Instance */
	VkInstance instance;
	
	const char * extensionNameArray[2]{VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME};
	
	VkInstanceCreateInfo instanceInfo = 
	{
		VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 	// VkStructureType             sType;
		NULL, 																		//	const void*                 pNext;
		0, 																			//	VkInstanceCreateFlags       flags;
		NULL, 																		//	const VkApplicationInfo*    pApplicationInfo;
		0,																				//	uint32_t                    enabledLayerCount;
		NULL, 																		//	const char* const*          ppEnabledLayerNames;
		2, 																			// uint32_t                    enabledExtensionCount;
		extensionNameArray 												//const char* const*          ppEnabledExtensionNames;
	}; 
	
	vkCreateInstance(&instanceInfo, NULL, &instance);		

	/* Create Device */
	VkDevice device;	
	
	std::vector<float> queuePriorities = { 1.0f };
	
	uint32_t queueFamilyIndex  = 0;
	
	VkDeviceQueueCreateInfo deviceQueueInfo = 
	{
		VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,     // VkStructureType              sType
		nullptr,                                        									// const void                  *pNext
		0,                                              										// VkDeviceQueueCreateFlags     flags
		queueFamilyIndex,                    							// uint32_t                     queueFamilyIndex
		static_cast<uint32_t>(queuePriorities.size()), 				// uint32_t                     queueCount
		&queuePriorities[0]                            								// const float                 *pQueuePriorities
	};
	
	const char * deviceExtensionNames[1] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
	VkDeviceCreateInfo deviceInfo =
	{
		VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, 	// VkStructureType sType;
		nullptr, 																// const void* pNext;
		0, 																		// VkDeviceCreateFlags flags;
		1, 																		// uint32_t queueCreateInfoCount;
		&deviceQueueInfo,												// const VkDeviceQueueCreateInfo* pQueueCreateInfos;
		0, 																		// uint32_t enabledLayerCount;
		nullptr, 																// const char* const* ppEnabledLayerNames;
		1, 																		// uint32_t enabledExtensionCount;
		deviceExtensionNames, 										// const char* const* ppEnabledExtensionNames;
		nullptr 																// const VkPhysicalDeviceFeatures* pEnabledFeatures;
	};
	
	VkPhysicalDevice physicalDevice;
	unsigned deviceCount = 1;	
	vkEnumeratePhysicalDevices(instance, &deviceCount, &physicalDevice);	
	vkCreateDevice(physicalDevice, &deviceInfo, NULL, &device);

	/*Create Queues */
	VkQueue graphicsQueue;
	VkQueue presentQueue;
	vkGetDeviceQueue(device, 0, 0, &graphicsQueue);	
	vkGetDeviceQueue(device, 0, 0, &presentQueue);		

	
	/*Create Surface*/
	VkSurfaceKHR surface;	
	
	VkWin32SurfaceCreateInfoKHR win32Info = 
	{
		VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, 		//VkStructureType                 sType;
		nullptr, 																						//const void*                     pNext;
		0, 																								//VkWin32SurfaceCreateFlagsKHR    flags;
		windowInstance,																			//HINSTANCE                       hinstance;
		window 																						//HWND                            hwnd;
	};
	
	vkCreateWin32SurfaceKHR(instance, &win32Info, NULL, &surface);	
	

	


	/*Create swapchain */
	VkSwapchainKHR swapchain;
	unsigned imageCount = 1;	

	VkExtent2D extent = {unsigned(win32Rect.right) , unsigned(win32Rect.bottom) };

	VkSwapchainCreateInfoKHR swapchainCreateInfo = 
	{
		VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, 	//VkStructureType                  sType;
		nullptr, 																				//const void*                      pNext;
		0, 																						//VkSwapchainCreateFlagsKHR        flags;
		surface, 																				//VkSurfaceKHR                     surface;
		imageCount, 																		//uint32_t                         minImageCount;
		VK_FORMAT_R8G8B8A8_UNORM, 										//VkFormat                         imageFormat;
		VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, 						//VkColorSpaceKHR                  imageColorSpace;
		extent, 																				//VkExtent2D                       imageExtent;
		0, 																						//uint32_t                         imageArrayLayers;
		0, 																						//VkImageUsageFlags                imageUsage;
		VK_SHARING_MODE_EXCLUSIVE, 										//VkSharingMode                    imageSharingMode;
		1,																						 	//uint32_t                         queueFamilyIndexCount;
		0, 																						//const uint32_t*                  pQueueFamilyIndices;
		(VkSurfaceTransformFlagBitsKHR)0, 									//VkSurfaceTransformFlagBitsKHR    preTransform;
		(VkCompositeAlphaFlagBitsKHR)0, 										//VkCompositeAlphaFlagBitsKHR      compositeAlpha;
		VK_PRESENT_MODE_MAILBOX_KHR, 									//VkPresentModeKHR                 presentMode;
		0, 																						//VkBool32                         clipped;
		NULL 																					//VkSwapchainKHR                   oldSwapchain;
	};

	vkCreateSwapchainKHR( device, &swapchainCreateInfo, NULL, &swapchain);
	std::vector<VkImage> swapchainImages;
	swapchainImages.resize(imageCount);	

	
	
	/*Create renderPass */
	VkRenderPass renderPass;	
	
	VkAttachmentDescription attachmentDescriptions[] = 
	{
		{
			0,                                   									// VkAttachmentDescriptionFlags   flags
			VK_FORMAT_R8G8B8A8_UNORM,               		// VkFormat                       format
			VK_SAMPLE_COUNT_1_BIT,               				// VkSampleCountFlagBits          samples
			VK_ATTACHMENT_LOAD_OP_CLEAR,         		// VkAttachmentLoadOp             loadOp
			VK_ATTACHMENT_STORE_OP_STORE,        		// VkAttachmentStoreOp            storeOp
			VK_ATTACHMENT_LOAD_OP_DONT_CARE,   	// VkAttachmentLoadOp             stencilLoadOp
			VK_ATTACHMENT_STORE_OP_DONT_CARE,  	// VkAttachmentStoreOp            stencilStoreOp
			VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,     	// VkImageLayout                  initialLayout;
			VK_IMAGE_LAYOUT_PRESENT_SRC_KHR      	// VkImageLayout                  finalLayout
		}
	};

	VkAttachmentReference colorAttachmentReferences[] = 
	{
		{
			0,                                          											// uint32_t                       attachment
			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL    	// VkImageLayout                  layout
		}
	};

	VkSubpassDescription subpassDescriptions[] = 
	{
		{
			0,                                         							// VkSubpassDescriptionFlags      flags
			VK_PIPELINE_BIND_POINT_GRAPHICS,          	// VkPipelineBindPoint            pipelineBindPoint
			0,                                         							// uint32_t                       inputAttachmentCount
			nullptr,                                    						// const VkAttachmentReference   *pInputAttachments
			1,                                          							// uint32_t                       colorAttachmentCount
			colorAttachmentReferences,                				// const VkAttachmentReference   *pColorAttachments
			nullptr,                                    						// const VkAttachmentReference   *pResolveAttachments
			nullptr,                                    						// const VkAttachmentReference   *pDepthStencilAttachment
			0,                                          							// uint32_t                       preserveAttachmentCount
			nullptr                                     						// const uint32_t*                pPreserveAttachments
		}
	};
	
	VkRenderPassCreateInfo renderPassInfo = 
	{
		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,   	// VkStructureType                sType
		nullptr,                                     									 	// const void                    *pNext
		0,                                           										 	// VkRenderPassCreateFlags        flags
		1,                                        							 	  				// uint32_t                       attachmentCount
		attachmentDescriptions,      							               		// const VkAttachmentDescription *pAttachments
		1,                                        							   					// uint32_t                       subpassCount
		subpassDescriptions,           							             		// const VkSubpassDescription    *pSubpasses
		0,                                        							   					// uint32_t                       dependencyCount
		nullptr                                							      				// const VkSubpassDependency     *pDependencies
	};
	
	if( vkCreateRenderPass( device, &renderPassInfo, nullptr, &renderPass ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to create renderpass. 
";
	}

	int asdf[5] = {1,2,3,4,5};

	
	/* create Framebuffer */
	std::vector<VkFramebuffer> frameBuffers;
	frameBuffers.resize(swapchainImages.size());	
	vkGetSwapchainImagesKHR( device, swapchain, &imageCount, &swapchainImages[0]);
	for( size_t i = 0; i < swapchainImages.size(); ++i ) 
	{
		VkImageViewCreateInfo imageViewCreateInfo = 
		{
			VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,   		// VkStructureType                sType
			nullptr,                                    										// const void                    *pNext
			0,                                          											// VkImageViewCreateFlags         flags
			swapchainImages[i],                      								 	// VkImage                        image
			VK_IMAGE_VIEW_TYPE_2D,                      						// VkImageViewType                viewType
			VK_FORMAT_R8G8B8A8_UNORM,                      				// VkFormat                       format
			{                                           											// VkComponentMapping             components
				VK_COMPONENT_SWIZZLE_IDENTITY,              			// VkComponentSwizzle             r
				VK_COMPONENT_SWIZZLE_IDENTITY,              			// VkComponentSwizzle             g
				VK_COMPONENT_SWIZZLE_IDENTITY,              			// VkComponentSwizzle             b
				VK_COMPONENT_SWIZZLE_IDENTITY               			// VkComponentSwizzle             a
			},
			{                                           											// VkImageSubresourceRange        subresourceRange
				VK_IMAGE_ASPECT_COLOR_BIT,                  				// VkImageAspectFlags             aspectMask
				0,                                          										// uint32_t                       baseMipLevel
				1,                                          										// uint32_t                       levelCount
				0,                                          										// uint32_t                       baseArrayLayer
				1                                           										// uint32_t                       layerCount
			}
		};

		VkImageView imageView;
		if( vkCreateImageView(device, &imageViewCreateInfo, nullptr, &imageView ) != VK_SUCCESS ) 
		{
			std::cout << "Failed to create image view for framebuffer.
";
		}

		VkFramebufferCreateInfo framebufferCreateInfo = 
		{
			VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,  		// VkStructureType                sType
			nullptr,                                 											// const void                    *pNext
			0,                                          											// VkFramebufferCreateFlags       flags
			renderPass,                          											// VkRenderPass                   renderPass
			1,                                          											// uint32_t                       attachmentCount
			&imageView,    																// const VkImageView             *pAttachments
			windowWidth,                      												// uint32_t                       width
			windowHeight,                     												// uint32_t                       height
			1                                           											// uint32_t                       layers
		};

		if( vkCreateFramebuffer(device, &framebufferCreateInfo, nullptr, &frameBuffers[i] ) != VK_SUCCESS ) 
		{
			std::cout << "Failed to create a framebuffer!
";
		}	
	}

	
	/*create Pipeline */
	std::vector<char> shaderCode;
	std::ifstream is ("vert.spv", std::ifstream::binary);
	if (is) 
	{
		// get length of file:
		is.seekg (0, is.end);
		int length = is.tellg();
		is.seekg (0, is.beg);
		shaderCode.resize(length);
		is.read (shaderCode.data(),length);

		if (is)
			std::cout << "all " << is.gcount() << " characters of vert.spv read successfully. 
";
		else
			std::cout << "error: only " << is.gcount() << " could be read
";
		is.close();
	}

	VkShaderModuleCreateInfo shaderModuleCreateInfo = 
	{
		VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,    			// VkStructureType                sType
		nullptr,                                        												// const void                    *pNext
		0,                                              													// VkShaderModuleCreateFlags      flags
		shaderCode.size(),                                    									// size_t                         codeSize
		reinterpret_cast<const uint32_t*>(&shaderCode[0])     			// const uint32_t                *pCode
	};

	VkShaderModule vertexShaderModule;
	if( vkCreateShaderModule(device, &shaderModuleCreateInfo, nullptr, &vertexShaderModule ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to create shader module
";
	}

  is.open("frag.spv", std::ifstream::binary);
  if (is) 
  {
		// get length of file:
		is.seekg (0, is.end);
		int length = is.tellg();
		is.seekg (0, is.beg);
		shaderCode.resize(length);
		is.read (shaderCode.data(),length);

    if (is)
		std::cout << "all " << is.gcount() << " characters of frag.spv read successfully. 
";
    else
		std::cout << "error: only " << is.gcount() << " could be read
";
		is.close();
  }

	shaderModuleCreateInfo = 
	{
		VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,    		// VkStructureType                sType
		nullptr,                                        											// const void                    *pNext
		0,                                              												// VkShaderModuleCreateFlags      flags
		shaderCode.size(),                                    								// size_t                         codeSize
		reinterpret_cast<const uint32_t*>(&shaderCode[0])     		// const uint32_t                *pCode
	};

	VkShaderModule fragmentShaderModule;
	if( vkCreateShaderModule(device, &shaderModuleCreateInfo, nullptr, &fragmentShaderModule ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to create shader module
";
	}
	
	std::vector<VkPipelineShaderStageCreateInfo> shaderStageCreateInfos = 
	{
		// Vertex shader
		{
			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,      	// VkStructureType                                sType
			nullptr,                                                    											// const void                                    *pNext
			0,                                                          												// VkPipelineShaderStageCreateFlags               flags
			VK_SHADER_STAGE_VERTEX_BIT,                                 						// VkShaderStageFlagBits                          stage
			vertexShaderModule,                                 											// VkShaderModule                                 module
			"main",                                                     											// const char                                    *pName
			nullptr                                                     											// const VkSpecializationInfo                    *pSpecializationInfo
		},
		// Fragment shader
		{
			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,        // VkStructureType                                sType
			nullptr,                                                    											// const void                                    *pNext
			0,                                                          												// VkPipelineShaderStageCreateFlags               flags
			VK_SHADER_STAGE_FRAGMENT_BIT,                               					// VkShaderStageFlagBits                          stage
			fragmentShaderModule,                               											// VkShaderModule                                 module
			"main",                                                     											// const char                                    *pName
			nullptr                                                     											// const VkSpecializationInfo                    *pSpecializationInfo
		}
	};
	
	VkPipelineVertexInputStateCreateInfo vertexInputStateCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,    	// VkStructureType                                sType
		nullptr,                                                      													// const void                                    *pNext
		0,                                                            														// VkPipelineVertexInputStateCreateFlags          flags;
		0,                                                            														// uint32_t                                       vertexBindingDescriptionCount
		nullptr,                                                      													// const VkVertexInputBindingDescription         *pVertexBindingDescriptions
		0,                                                            														// uint32_t                                       vertexAttributeDescriptionCount
		nullptr                                                       													// const VkVertexInputAttributeDescription       *pVertexAttributeDescriptions
	};
	
	VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,  	// VkStructureType                                sType
		nullptr,                                                      														// const void                                    *pNext
		0,                                                            															// VkPipelineInputAssemblyStateCreateFlags        flags
		VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                          							// VkPrimitiveTopology                            topology
		VK_FALSE                                                      													// VkBool32                                       primitiveRestartEnable
	};	
	
	VkViewport viewport = 
	{
		0.0f,                                   			// float                                          x
		0.0f,                                     		// float                                          y
		float(windowWidth),      				// float                                          width
		float(windowHeight),       				// float                                          height
		0.0f,                                     		// float                                          minDepth
		1.0f                                      		// float                                          maxDepth
	};

	VkRect2D scissor = 
	{
		{                                                             		// VkOffset2D                                     offset
			0,                                                            	// int32_t                                        x
			0                                                             	// int32_t                                        y
		},
		{                                                             		// VkExtent2D                                     extent
			windowWidth,                             				// int32_t                                        width
			windowHeight                              				// int32_t                                        height
		}
	};

	VkPipelineViewportStateCreateInfo viewportStateCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,        	// VkStructureType                                sType
		nullptr,                                                      												// const void                                    *pNext
		0,                                                            													// VkPipelineViewportStateCreateFlags             flags
		1,                                                            													// uint32_t                                       viewportCount
		&viewport,                                                    											// const VkViewport                              *pViewports
		1,                                                            													// uint32_t                                       scissorCount
		&scissor                                                      												// const VkRect2D                                *pScissors
	};
			
	VkPipelineRasterizationStateCreateInfo rasterizationStateCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,   		// VkStructureType                                sType
		nullptr,                                                      														// const void                                    *pNext
		0,                                                            															// VkPipelineRasterizationStateCreateFlags        flags
		VK_FALSE,                                                     													// VkBool32                                       depthClampEnable
		VK_FALSE,                                                     													// VkBool32                                       rasterizerDiscardEnable
		VK_POLYGON_MODE_FILL,                                         										// VkPolygonMode                                  polygonMode
		VK_CULL_MODE_BACK_BIT,                                        										// VkCullModeFlags                                cullMode
		VK_FRONT_FACE_COUNTER_CLOCKWISE,                              							// VkFrontFace                                    frontFace
		VK_FALSE,                                                     													// VkBool32                                       depthBiasEnable
		0.0f,                                                         														// float                                          depthBiasConstantFactor
		0.0f,                                                         														// float                                          depthBiasClamp
		0.0f,                                                         														// float                                          depthBiasSlopeFactor
		1.0f                                                          														// float                                          lineWidth
	};
	
	VkPipelineMultisampleStateCreateInfo multisampleStateCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,     	// VkStructureType                                sType
		nullptr,                                                      													// const void                                    *pNext
		0,                                                            														// VkPipelineMultisampleStateCreateFlags          flags
		VK_SAMPLE_COUNT_1_BIT,                                        									// VkSampleCountFlagBits                          rasterizationSamples
		VK_FALSE,                                                     												// VkBool32                                       sampleShadingEnable
		1.0f,                                                         													// float                                          minSampleShading
		nullptr,                                                     													// const VkSampleMask                            *pSampleMask
		VK_FALSE,                                                     												// VkBool32                                       alphaToCoverageEnable
		VK_FALSE                                                      												// VkBool32                                       alphaToOneEnable
	};

	VkPipelineColorBlendAttachmentState colorBlendAttachmentState = 
	{
		VK_FALSE,                                                    											// VkBool32                                       blendEnable
		VK_BLEND_FACTOR_ONE,                                          								// VkBlendFactor                                  srcColorBlendFactor
		VK_BLEND_FACTOR_ZERO,                                         								// VkBlendFactor                                  dstColorBlendFactor
		VK_BLEND_OP_ADD,                                              									// VkBlendOp                                      colorBlendOp
		VK_BLEND_FACTOR_ONE,                                          								// VkBlendFactor                                  srcAlphaBlendFactor
		VK_BLEND_FACTOR_ZERO,                                         								// VkBlendFactor                                  dstAlphaBlendFactor
		VK_BLEND_OP_ADD,                                              									// VkBlendOp                                      alphaBlendOp
		VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT |       // VkColorComponentFlags                          colorWriteMask
		VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
	};

	VkPipelineColorBlendStateCreateInfo colorBlendStateCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,     	// VkStructureType                                sType
		nullptr,                                                      													// const void                                    *pNext
		0,                                                            														// VkPipelineColorBlendStateCreateFlags           flags
		VK_FALSE,                                                     												// VkBool32                                       logicOpEnable
		VK_LOGIC_OP_COPY,                                             										// VkLogicOp                                      logicOp
		1,                                                            														// uint32_t                                       attachmentCount
		&colorBlendAttachmentState,                                										// const VkPipelineColorBlendAttachmentState     *pAttachments
		{ 0.0f, 0.0f, 0.0f, 0.0f }                                    												// float                                          blendConstants[4]
	};
		
	VkPipelineLayoutCreateInfo layoutCreateInfo = 
	{
		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,  		// VkStructureType                sType
		nullptr,                                        											// const void                    *pNext
		0,                                              												// VkPipelineLayoutCreateFlags    flags
		0,                                             												// uint32_t                       setLayoutCount
		nullptr,                                													// const VkDescriptorSetLayout   *pSetLayouts
		0,                                              												// uint32_t                       pushConstantRangeCount
		nullptr                       		 														// const VkPushConstantRange     *pPushConstantRanges
	};

	VkPipelineLayout pipelineLayout;
	if( vkCreatePipelineLayout(device, &layoutCreateInfo, nullptr, &pipelineLayout ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to create a pipeline layout!
";
	}

	VkGraphicsPipelineCreateInfo pipelineCreateInfo = 
	{
		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,              	// VkStructureType                                sType
		nullptr,                                                      											// const void                                    *pNext
		0,                                                            												// VkPipelineCreateFlags                          flags
		static_cast<uint32_t>(shaderStageCreateInfos.size()),      				// uint32_t                                       stageCount
		&shaderStageCreateInfos[0],                                								// const VkPipelineShaderStageCreateInfo         *pStages
		&vertexInputStateCreateInfo,                              									// const VkPipelineVertexInputStateCreateInfo    *pVertexInputState;
		&inputAssemblyStateCreateInfo,                            								// const VkPipelineInputAssemblyStateCreateInfo  *pInputAssemblyState
		nullptr,                                                      											// const VkPipelineTessellationStateCreateInfo   *pTessellationState
		&viewportStateCreateInfo,                                  									// const VkPipelineViewportStateCreateInfo       *pViewportState
		&rasterizationStateCreateInfo,                             									// const VkPipelineRasterizationStateCreateInfo  *pRasterizationState
		&multisampleStateCreateInfo,                               								// const VkPipelineMultisampleStateCreateInfo    *pMultisampleState
		nullptr,                                                      											// const VkPipelineDepthStencilStateCreateInfo   *pDepthStencilState
		&colorBlendStateCreateInfo,                               									// const VkPipelineColorBlendStateCreateInfo     *pColorBlendState
		nullptr,                                                      											// const VkPipelineDynamicStateCreateInfo        *pDynamicState
		pipelineLayout,                                        												// VkPipelineLayout                               layout
		renderPass,                                            												// VkRenderPass                                   renderPass
		0,                                                            												// uint32_t                                       subpass
		VK_NULL_HANDLE,                                               								// VkPipeline                                     basePipelineHandle
		-1                                                            												// int32_t                                        basePipelineIndex
	};

	VkPipeline graphicsPipeline;
	if( vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipelineCreateInfo, nullptr, &graphicsPipeline ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to create a graphics pipeline!
" ;
	}
	


	/*create Synchronization objects */
	VkImageSubresourceRange imageSubresourceRange = 
	{
		VK_IMAGE_ASPECT_COLOR_BIT,     		// VkImageAspectFlags             aspectMask
		0,                                              			// uint32_t                       baseMipLevel
		1,                                              			// uint32_t                       levelCount
		0,                                              			// uint32_t                       baseArrayLayer
		1                                               			// uint32_t                       layerCount
	};

	VkClearValue clearValue = 
	{
		{ 1.0f, 0.0f, 0.0f, 0.0f },                     	// VkClearColorValue              color
	};

	VkImageMemoryBarrier barrierFromDrawToPresent = 
	{
		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,       	// VkStructureType              sType
		nullptr,                                      										// const void                  *pNext
		VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,         		// VkAccessFlags                srcAccessMask
		VK_ACCESS_MEMORY_READ_BIT,                    					// VkAccessFlags                dstAccessMask
		VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,              			// VkImageLayout                oldLayout
		VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,              			// VkImageLayout                newLayout
		0,               																		// uint32_t                     srcQueueFamilyIndex
		0,               																		// uint32_t                     dstQueueFamilyIndex
		swapchainImages[0],                         								// VkImage                      image
		imageSubresourceRange                       							// VkImageSubresourceRange      subresourceRange
	};
	
    VkImageMemoryBarrier barrierFromPresentToDraw = 
	{
		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,     		// VkStructureType                sType
		nullptr,                                    										// const void                    *pNext
		VK_ACCESS_MEMORY_READ_BIT,                  					// VkAccessFlags                  srcAccessMask
		VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,       		// VkAccessFlags                  dstAccessMask
		VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,            				// VkImageLayout                  oldLayout
		VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,            				// VkImageLayout                  newLayout
		0,              																		// uint32_t                       srcQueueFamilyIndex
		0,             																		// uint32_t                       dstQueueFamilyIndex
		swapchainImages[1],                       								// VkImage                        image
		imageSubresourceRange                     								// VkImageSubresourceRange        subresourceRange
	};
	
		VkSemaphoreCreateInfo semaphoreCreateInfo = 
	{
		VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,      	// VkStructureType          sType
		nullptr,                                      										// const void*              pNext
		0                                             											// VkSemaphoreCreateFlags   flags
    };
	
	VkSemaphore imageAvailableSemaphore;
	VkSemaphore renderingFinishedSemaphore;

    if( (vkCreateSemaphore( device, &semaphoreCreateInfo, nullptr, &imageAvailableSemaphore ) != VK_SUCCESS) ||
        (vkCreateSemaphore( device, &semaphoreCreateInfo, nullptr, &renderingFinishedSemaphore ) != VK_SUCCESS) ) 
	{
		std::cout << "Could not create semaphores!" << std::endl;
	}



	/*create and allocate Command Buffer */
	std::vector<VkCommandBuffer> commandBuffers;
	VkCommandPool commandPool;
	commandBuffers.resize(imageCount);
	VkCommandPoolCreateInfo comandPoolCreateInfo = 
	{
		VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,     		// VkStructureType                sType
		nullptr,                                        											// const void                    *pNext
		0,                                              												// VkCommandPoolCreateFlags       flags
		queueFamilyIndex                              										// uint32_t                       queueFamilyIndex
	};

	if( vkCreateCommandPool(device, &comandPoolCreateInfo, nullptr, &commandPool ) != VK_SUCCESS )
	{
		std::cout << "Failed to create a command pool.
";
	}

	VkCommandBufferAllocateInfo commandBufferAllocateInfo = 
	{
		VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, 		// VkStructureType                sType
		nullptr,                                        												// const void                    *pNext
		commandPool,                                           									// VkCommandPool                  commandPool
		VK_COMMAND_BUFFER_LEVEL_PRIMARY,                						// VkCommandBufferLevel           level
		imageCount                                         											// uint32_t                       bufferCount
	};

	if( vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, commandBuffers.data() ) != VK_SUCCESS ) 
	{
		std::cout << "Failed to allocate command buffers.
";
	}


	VkCommandBufferBeginInfo graphicsCommandBufferBeginInfo = 
	{
		VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    		// VkStructureType                        sType
		nullptr,                                        											// const void                            *pNext
		VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,   	// VkCommandBufferUsageFlags              flags
		nullptr                                         											// const VkCommandBufferInheritanceInfo  *pInheritanceInfo
	};
	
	for( size_t i = 0; i < commandBuffers.size(); ++i ) 
	{
		vkBeginCommandBuffer( commandBuffers[i], &graphicsCommandBufferBeginInfo );
		vkCmdPipelineBarrier( commandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrierFromPresentToDraw );

		VkRenderPassBeginInfo renderPassBeginInfo = 
		{
			VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,  	// VkStructureType                sType
			nullptr,                                      									// const void                    *pNext
			renderPass,                            										// VkRenderPass                   renderPass
			frameBuffers[i],          													// VkFramebuffer                  framebuffer
			{                                             										// VkRect2D                       renderArea
				{                                           									// VkOffset2D                     offset
					0,                                          								// int32_t                        x
					0                                           								// int32_t                        y
				},
				{                                           									// VkExtent2D                     extent
					windowWidth,                                        				// int32_t                        width
					windowHeight,                                        				// int32_t                        height
				}
			},
			1,                                            										// uint32_t                       clearValueCount
			&clearValue                                 									// const VkClearValue            *pClearValues
		};

		vkCmdBeginRenderPass( commandBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE );
		vkCmdBindPipeline( commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline );
		vkCmdDraw( commandBuffers[i], 3, 1, 0, 0 );
		vkCmdEndRenderPass( commandBuffers[i] );
		vkCmdPipelineBarrier( commandBuffers[i], VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, 1, &barrierFromDrawToPresent );
		vkEndCommandBuffer( commandBuffers[i] );
	}


	
	
	uint32_t imageIndex;
	VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT;
	VkSubmitInfo submitInfo = 
	{
		VK_STRUCTURE_TYPE_SUBMIT_INFO,   			// VkStructureType              sType
		nullptr,                                      						// const void                  *pNext
		1,                                            							// uint32_t                     waitSemaphoreCount
		&imageAvailableSemaphore,                   			// const VkSemaphore           *pWaitSemaphores
		&waitDstStageMask,                         				// const VkPipelineStageFlags  *pWaitDstStageMask;
		1,                                            							// uint32_t                     commandBufferCount
		&commandBuffers[imageIndex],  						// const VkCommandBuffer       *pCommandBuffers
		1,                                            							// uint32_t                     signalSemaphoreCount
		&renderingFinishedSemaphore                 			// const VkSemaphore           *pSignalSemaphores
	};

	vkAcquireNextImageKHR( device, swapchain, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex );
	vkQueueSubmit( graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE );	
	
		VkPresentInfoKHR presentInfo = 
	{
		VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,     		// VkStructureType              sType
		nullptr,                                      								// const void                  *pNext
		1,                                            									// uint32_t                     waitSemaphoreCount
		&renderingFinishedSemaphore,                					// const VkSemaphore           *pWaitSemaphores
		1,                                            									// uint32_t                     swapchainCount
		&swapchain,                                 	 						// const VkSwapchainKHR        *pSwapchains
		&imageIndex,                                 							// const uint32_t              *pImageIndices
		nullptr                                       								// VkResult                    *pResults
	};

	
	MSG message;
	PeekMessage(&message, 0, 0, 0, PM_REMOVE);
	while (message.message != WM_QUIT) 
	{
		TranslateMessage(&message);
		DispatchMessage(&message);	
		vkQueuePresentKHR( presentQueue, &presentInfo);		
		PeekMessage(&message, 0, 0, 0, PM_REMOVE);
	}		

	vkResetCommandPool( device, commandPool, 0);
	vkDestroySwapchainKHR( device, swapchain,NULL);
	vkDestroyDevice( device, NULL);
	vkDestroyInstance( instance, NULL);
	return 0;
}


Here is where you can find the code the last two links are the .spv shader files:
https://ufile.io/k1rq5

https://ufile.io/f821i

https://ufile.io/15edx

What’s the crash message and callstack (incl. argument values)?

Okay so I should have mentioned sometimes it crashes sometimes it just displays a black screen with no triangle and I’ve managed to isolate the crash to the queue submit. I’m not sure what you mean by callstack but here are the crash messages:

Problem signature:
Problem Event Name: APPCRASH
Application Name: vulkan1.exe
Application Version: 0.0.0.0
Application Timestamp: 5b29977d
Fault Module Name: nvoglv64.dll
Fault Module Version: 10.18.13.6472
Fault Module Timestamp: 56f0a3bd
Exception Code: c0000005
Exception Offset: 0000000000e90dcc
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 6eb2
Additional Information 2: 6eb286788ea90c30636d24abee1d81dc
Additional Information 3: 67a8
Additional Information 4: 67a8bd4b34ccfd0aa8ce81d3be0e650f

Problem signature:
Problem Event Name: APPCRASH
Application Name: vulkan1.exe
Application Version: 0.0.0.0
Application Timestamp: 5b299908
Fault Module Name: nvoglv64.dll
Fault Module Version: 10.18.13.6472
Fault Module Timestamp: 56f0a3bd
Exception Code: c0000005
Exception Offset: 0000000000e90dcc
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 6eb2
Additional Information 2: 6eb286788ea90c30636d24abee1d81dc
Additional Information 3: 4b79
Additional Information 4: 4b795e518a247d60419554c39ada592e

Problem signature:
Problem Event Name: APPCRASH
Application Name: vulkan1.exe
Application Version: 0.0.0.0
Application Timestamp: 5b299ade
Fault Module Name: nvoglv64.dll
Fault Module Version: 10.18.13.6472
Fault Module Timestamp: 56f0a3bd
Exception Code: c0000005
Exception Offset: 0000000000e90dcc
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 6eb2
Additional Information 2: 6eb286788ea90c30636d24abee1d81dc
Additional Information 3: 4b79
Additional Information 4: 4b795e518a247d60419554c39ada592e

Dude.
It is also called backtrace in your favorite gdb. Look it up. You won’t be able to debug anything ever without knowing what a call stack is.

Add a -g to your compilation. Run gdb yourexecutable. Enter run command after which it should crash. Enter bt to know how you get to the crash, and which arguments were used.

Anyway, I see plenty of problems in your code. Crashes like this are indicative of uninitialized variables. Visual Studio does help you here by defining them to a bad (nonzero) value in Debug mode, which usually gives deterministic crashes; not sure how it works in g++. Or because OOBA. Again VS helps you here by having range guards in Debug mode; don’t know about g++.

Some notes:

  • You can use canonical #include &lt;vulkan/vulkan.h&gt; as you have include path added by -I compilation flag.
  • Glad to see you came to the dark side of using tabs. Use them only for indentation though; for alignment use spaces. Your comments are misaligned.
  • Your WndProc case WM_DESTROY is missing a return. Also, as all the cases are supposed to return, break is unnecessary there and confusing.
  • applicationName should be LPCTSTR
  • Uninitialized variable windowInstance is used several times instead of hInstance
  • Uninitialized variable imageIndex is used in submitInfo. The vkAcquireNextImageKHR should be before your submitInfo.
  • barrierFromPresentToDraw contains swapchainImages[1], which is likely wrong and triggers OOBA warning for me.

OK, try to fix this up. Compile with -std=c++14 -Wpedantic -Wall -Wextra to get some extra compile-time warnings. And get back to me if you won’t still find the culprit.

PS: It crashes in the driver, which means bad parameter values, or a driver bug. 10.18.13.6472 seems old by a quick Google search. Update your driver to the latest from the NVIDIA site.

Alright thanks, I’ll try and do the things you said. I know I’m not very good at this, I’m a statistician not a software engineer. The only programming book I’ve read is c++ primer. I have a preference for minimalism that is probably irrational to a degree so I really just like the mingw distro that nuwen made because it’s just ready to go and I don’t have to wonder how I got it working if I change installations, there’s just too many options of different modules to install for the base mingw. I also don’t like visual studio for the same reason I don’t like CUDA, even though I run an NVidia GPU I don’t want to be tied to one GPU vendor, similarly I don’t want to be tied to one OS.

I’ve neglected learning a lot of the tools that software developers use that are intended to make their lives easier. Like make or cmake, I tried to use them a few times, had trouble figuring out how to get it to work and then when I did apparently get it to work I had no confidence that I did it right and got frustrated and gave up and avoid using it whenever possible. I’ll take a look at this GNU debugger thing though, it looks interesting and I didn’t know it existed.

No worries. C++ community is a bunch of jerk-faces that shall correct you for the smallest infraction. You shall not stay “not very good” for long!
Calling a 1000 pages book a “primer” should probably be a crime :p. Practice (and code review from others) helps best…

My problem with “minimalism” as imagined by terminal tools such as g++ or gdb is that each time I need to use them I spend two days in manuals. And worst thing is next time I need them I forget all of those arbitrarily named flags and commands, and spend two days in manuals again. In IDE it feels much easier as one can use one’s oversized human visual cortex. Multiplatformish Netbeans IDE C++ plugin also seemed decent to me. But whatever works for you.

Like make or cmake, I tried to use them a few times, had trouble figuring out how to get it to work and then when I did apparently get it to work I had no confidence that I did it right and got frustrated and gave up and avoid using it whenever possible.

cmake does not make lives much easier (each use = two days in manuals), but it makes things (esp. large projects) humanely possible. If you had to compile bigish project directly with g++, then do the same with each of its dependencies (and their dependencies), that is a good way to develop PTSD too.

I’ll take a look at this GNU debugger thing though, it looks interesting and I didn’t know it existed.

Debugging in terminal\console can be a pain though. You have been warned.

[HR][/HR]

I forgot to mention one other thing. In Vulkan during development phase Validation Layers (i.e. VK_LAYER_LUNARG_standard_validation) should always be used.
That is either done externally (the easy way) by setting environment variable VK_INSTANCE_LAYERS as written in Lunarg Docs, or the hard way be enabling VK_LAYER_LUNARG_standard_validation during vkCreateInstance and using it with the VK_EXT_debug_report or VK_EXT_debug_utils extension as prescribed in the Vulkan specification.

PS: Vulkan is not a best pick for people learning programming. It is not really a typical library, and also requires a bit of discipline to use. You should at least always check VkResult if returned by the API. There is the Validation Layers as a safety net, but as they are not complete you should avoid making too many errors, – especially synchronization errors can be tough (and sometimes the program even seems like it works on some GPU, but not others, which is a problem hard to discover and fix).