Problem keeping GLFW window open


#1

My apologies in advance for the length of this request for help but I believe that anyone kind enough to reply would prefer too much information rather than too little.
I have started to learn Vulkan using the You Tube videos posted by Brotcrunsher. There are 115 of these and I have found the first 21 very useful. Number [022] concerns creating a GLFW window. He uses visual Studio 2015 , LunarG SDK 1.0.36 and GLFW 3.2.1. I have a Toshiba p75 64 bit laptop Visual C++ 2017 Community edition, LunarG SDK 1.0.61 and GLFW 3.2.1. In a previous conversation in this forum ,I was told that vc2015 binaries would work with VC2017. I have used the 32 bit binaries since I was unable to build my project with the 64 bit version.
Here is all the GLFW code for Tutorial [022}. Except for main , which is complete, I have excluded all the Vulkan related code . The program as written produces a completely white window of the appropriate size with title and icons and then immediately throws an exception:0x0114AE2F in HELLO VULKAN.exe:0xC0000005; Access Violation reading location 0x00000014.

Note: formating fixed by admin

    // #define GLFW_INCLUDE_VULKAN //DOES NOT BUILD
      #include <GLFW\glfw3.h>
     #include "vulkan\vulkan.h" // REQUIRED TO BUILD

    GLFWWindow  *window;

    void startGlfw()
     {
     glfwInit();
     glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
     glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
     glfwCreateWindow(800,600,"HELLO VULKAN",nullptr,nullptr);
     }

    void mainLoop()
    {
     while(!glfwWindowShouldClose(window))
         {
         glfwPollEvents();
         }
    }

   void shutdownGlfw()
   { 
    glfwDestroyWindow(window);
   }

  int main( int argc, char** argv)
  {
   startGlfw();
   startVulkan();
   mainLoop();
   shutdownVulkan();
   shutdownGlfw();
   return 0;
   }

If,in mainLoop, true is substituted for !gflwWindowShouldClose(window) then the window persists. Minimize (-) works,maximize(greyed out square) does not .Presumably because the window is not resizable. If the cursor is placed above the close (X) icon ,the surround turns red .Clicking reduces the colour intensity but does not close the window. Output from the Vulkan code for the previous tutorials is correct and may be read from the debug window. By closing the debug window normally the program exits with code 0xc00013a.
Since this is the first time that I have used GLFW ,I have probably done something very stupid. If anyone has any suggestion about correcting my problem to produce a normally functioning window I would be most grateful.

Thanks in advance

JOHN


#2

More information is always better than less, thank you!

It looks like you are not setting the GLFWWindow *window; value, but are using it in two functions. You need to set it as follows:

window = glfwCreateWindow(800,600,"HELLO VULKAN",nullptr,nullptr);

Hopefully this should help get you started. Please do come back to the forum with further questions if you need more help.


#3

Many thanks for the correction. The exception is no longer thrown so the window remains open. Unfortunately it still does not close normally. I suspect that the problem has something to do with the linker input set up in the property pages. I am running Windows 10 and have selected glfw3.lib from the vc2015 folder for that . However I did try ringing changes on the folder contents for that and nothing seemed to work . Your expert advice would be very much appreciated.

 yours sincerely

 JOHN

#4

Not closing seems odd given it looks like your code is handling event polling and window close correctly - perhaps you could paste the full source with the window creation correction for me to check? Note that to post source code it’s easiest to encapsulate the code with ```:

```
// Code here.
```

This isn’t likely to be an error in the linker set up, since then you would usually get link errors and the program would not run.


#5

Dear Doug,
Are you sure? Remember I am using Visual C++ 2017 and there is no folder targeting this version in the GLFW download . I have no experience building libraries with CMake and have simply used the vc2015 libraries as is . I now believe that this is my error. Is this correct? If so I would need very complete instructions as to how to proceed.
’’’


#6

Sorry about this .I am having trouble entering the source code

Note: formating below fixed by admin

//HELLO VULKAN X86//

#include <iostream>
#include <vector>

//#define GLFW_INCLUDE_VULKAN   //BUILD FAILS

#include<GLFW\glfw3.h>

#define VK_USE_PLATFORM_WIN32_KHR "VK_KHR_Win32_surface"

//#define GLFW_VULKAN_STATIC

#include "vulkan\vulkan.h"     //REQUIRED TO BUILD

void ASSERT_VULKAN(VkResult value)
{
	if (value != VK_SUCCESS) { std::cout << "ASSERT FAILED\n" << value; }
}

void printStats(VkPhysicalDevice &device)
{
	VkPhysicalDeviceProperties properties;
	vkGetPhysicalDeviceProperties(device, &properties);

	uint32_t apiVer = properties.apiVersion;

	std::cout << "\n           HELLO VULKAN X86 PRINT STATS\n\n";
	std::cout << " Name:                      " << properties.deviceName << "\n";
	std::cout << " API Version:               " << properties.apiVersion << "\n";
	std::cout << " Driver Version:            " << properties.driverVersion << "\n";
  	std::cout << " Device ID:                 " << properties.deviceID << "\n";
	std::cout << " Device Type:               " << properties.deviceType << "\n";
	std::cout << " Discrete Queue Priorities: " << properties.limits.discreteQueuePriorities << "\n";

	VkPhysicalDeviceFeatures features;
	vkGetPhysicalDeviceFeatures(device, &features);

	std::cout << " Geometry Shader :          " << features.geometryShader << "\n";
	std::cout << " Tessellation Shader :      " << features.tessellationShader << "\n";

	VkPhysicalDeviceMemoryProperties memProps;

	uint32_t numberofQueueFamilies = 0;
	uint32_t queueCount = 0;


	vkGetPhysicalDeviceMemoryProperties(device, &memProps);
	
	vkGetPhysicalDeviceQueueFamilyProperties(device, &numberofQueueFamilies, nullptr);

	VkQueueFamilyProperties *familyProperties = new VkQueueFamilyProperties[numberofQueueFamilies];  // BETTER USE STD::VECTOR

	vkGetPhysicalDeviceQueueFamilyProperties(device, &numberofQueueFamilies, familyProperties);

	std::cout << " Number of Queue Families:  " << numberofQueueFamilies << "\n";

	for (uint32_t i = 0; i < numberofQueueFamilies; i++)
	{
		std::cout << "\n Queue Family # " << i << " \n";
		std::cout << " VK_QUEUE_GRAPHICS_BIT:        " << ((familyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) << "\n";
		std::cout << " VK_QUEUE_COMPUTE_BIT:         " << ((familyProperties[i].queueFlags & VK_QUEUE_COMPUTE_BIT) != 0) << "\n";
		std::cout << " VK_QUEUE_TRANSFER_BIT:        " << ((familyProperties[i].queueFlags & VK_QUEUE_TRANSFER_BIT) != 0) << "\n";
		std::cout << " VK_QUEUE_SPARSE_BINDING_BIT:  " << ((familyProperties[i].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) != 0) << "\n";
		std::cout << " Queue Count:                  " << familyProperties[i].queueCount << "\n";
		std::cout << " Timestamp Valid Bits:         " << familyProperties[i].timestampValidBits << "\n";

		uint32_t width = familyProperties[i].minImageTransferGranularity.width;

		uint32_t height = familyProperties[i].minImageTransferGranularity.height;

		uint32_t depth = familyProperties[i].minImageTransferGranularity.depth;

		std::cout << " Min Image timestamp Granularity: " << width << ", " << height << ", " << depth << "\n";

   }

	delete[] familyProperties; 
}

VkApplicationInfo appInfo;

VkInstance instance;

VkSurfaceKHR surface;

VkDevice device;

GLFWwindow *window;


void startGlfw()
{
	glfwInit();

	glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

	glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

	window = glfwCreateWindow(1000, 800, "   HELLO VULKAN X86   ", nullptr, nullptr);
}

//int main(int argc, char** argv)

void startVulkan()
{
	//APPLICATION INFO//

	appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
	appInfo.pNext = NULL;
	appInfo.pApplicationName = "VULKAN TUTORIAL";
	appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
	appInfo.pEngineName = "JOHN'S MACHINE";
	appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
	appInfo.apiVersion = VK_API_VERSION_1_0;

	uint32_t numberofLayers = 0;

	vkEnumerateInstanceLayerProperties(&numberofLayers, nullptr);

	VkLayerProperties *layers = new VkLayerProperties[numberofLayers];

	vkEnumerateInstanceLayerProperties(&numberofLayers, layers);

	std::cout << "\n              HELLO VULKAN X86 \n\n DEVICE PROPERTIES\n";

	std::cout << "\n Number of Instance Layers: " << numberofLayers << "\n";

	for (uint32_t i = 0; i < numberofLayers; i++)
	{
		std::cout << " Name:                    " << layers[i].layerName << "\n";
		std::cout << " Spec Version:            " << layers[i].specVersion << "\n";
		std::cout << " Implementation Version:  " << layers[i].implementationVersion << "\n";
		std::cout << " Description:             " << layers[i].description << "\n\n";
	}

	uint32_t numberofExtensions = 0;

	vkEnumerateInstanceExtensionProperties(nullptr, &numberofExtensions, nullptr);

	VkExtensionProperties *extensions = new VkExtensionProperties[numberofExtensions];

	vkEnumerateInstanceExtensionProperties(nullptr, &numberofExtensions, extensions);

	std::cout << "\n Number of Extensions:      " << numberofExtensions << "\n";

	for (uint32_t i = 0; i < numberofExtensions; i++)
	{
		std::cout << " Name:                    " << extensions[i].extensionName << "\n";

		std::cout << " Spec Version:            " << extensions[i].specVersion << "\n";
	}

	const std::vector<const char*> validationLayers = { "VK_LAYER_LUNARG_standard_validation" };

	const std::vector<const char*> usedExtensions = { "VK_KHR_surface", VK_KHR_WIN32_SURFACE_EXTENSION_NAME };


	//INSTANCE INFO//

	VkInstanceCreateInfo instanceInfo;

	instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
	instanceInfo.pNext = nullptr;
	instanceInfo.flags = 0;
	instanceInfo.pApplicationInfo = &appInfo;
	instanceInfo.enabledLayerCount = 0;
	instanceInfo.ppEnabledLayerNames = nullptr;
	instanceInfo.enabledExtensionCount = usedExtensions.size();
	instanceInfo.ppEnabledExtensionNames = usedExtensions.data();

	//INSTANCE CREATION//

	VkResult result = vkCreateInstance(&instanceInfo, nullptr, &instance);

	//SURFACE INFO//

	VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;

	surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR;

	surfaceCreateInfo.pNext = nullptr;

	surfaceCreateInfo.flags = 0;

	surfaceCreateInfo.hinstance = nullptr;

	surfaceCreateInfo.hwnd = nullptr;

	ASSERT_VULKAN(result);

	//UNSURE CONCERNING ORDER OF SURFACE AND PROCADDR HERE//

	//VkSurfaceKHR surface;

	result = vkCreateWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
	ASSERT_VULKAN(result);


	vkGetInstanceProcAddr(instance, "");

	uint32_t numberofPhysicalDevices = 0;

	result = vkEnumeratePhysicalDevices(instance, &numberofPhysicalDevices, nullptr);
	ASSERT_VULKAN(result);

	//VkPhysicalDevice *physicalDevices = new VkPhysicalDevice[numberofPhysicalDevices];

	std::vector<VkPhysicalDevice> physicalDevices;

	physicalDevices.resize(numberofPhysicalDevices);

	result = vkEnumeratePhysicalDevices(instance, &numberofPhysicalDevices, physicalDevices.data());
	ASSERT_VULKAN(result);

	for (uint32_t i = 0; i < numberofPhysicalDevices; i++)
	{
		printStats(physicalDevices[i]);
	}

	//QUEUE INFO//

	float queuePriorities[] = { 1.0f, 1.0f, 1.0f, 1.0f };

	VkDeviceQueueCreateInfo deviceQueueCreateInfo;

	deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
	deviceQueueCreateInfo.pNext = nullptr;
	deviceQueueCreateInfo.flags = 0;
	deviceQueueCreateInfo.queueFamilyIndex = 0; // TO DO SELECT CORRECT FAMILY INDEX
	deviceQueueCreateInfo.queueCount = 4;       // TO DO CHECK IF THIS IS A VALID NUMBER
	deviceQueueCreateInfo.pQueuePriorities = nullptr;       // TO DO CHECK IF THIS IS A VALID NUMBER

	//PHYSICAL DEVICE//

	VkPhysicalDeviceFeatures usedFeatures = {};

	VkDeviceCreateInfo deviceCreateInfo;

	deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
	deviceCreateInfo.pNext = nullptr;
	deviceCreateInfo.flags = 0;
	deviceCreateInfo.queueCreateInfoCount = 1;
	deviceCreateInfo.pQueueCreateInfos = &deviceQueueCreateInfo;
	deviceCreateInfo.enabledLayerCount = 0;
	deviceCreateInfo.ppEnabledLayerNames = nullptr;
	deviceCreateInfo.enabledExtensionCount = 0;
	deviceCreateInfo.ppEnabledExtensionNames = nullptr;
	deviceCreateInfo.pEnabledFeatures = &usedFeatures;

	result = vkCreateDevice(physicalDevices[0], &deviceCreateInfo, nullptr, &device);
	ASSERT_VULKAN(result);

	VkQueue queue;

	vkGetDeviceQueue(device, 0, 0, &queue);

	vkDeviceWaitIdle(device);

	vkDestroyDevice(device, nullptr);
	vkDestroySurfaceKHR(instance, surface, nullptr);
	vkDestroyInstance(instance, nullptr);


	delete[] layers;

	delete[] extensions;
}



void mainLoop()
{

	while (true)//(!glfwWindowShouldClose(window)) //THIS THROWS EXCEPTION (true) WINDOW PERSISTS BUT CAN'T BE CLOSED
	{		
		glfwPollEvents();
	}
	
}

void shutdownVulkan()
{

	vkDeviceWaitIdle(device);

	vkDestroyDevice(device, nullptr);

	vkDestroySurfaceKHR(instance, surface, nullptr);
	
	vkDestroyInstance(instance, nullptr);


}

void shutdownGlfw()
{
	glfwDestroyWindow(window);
}

int main(int argc, char** argv)
{
	startGlfw();

    startVulkan();

	mainLoop();

	shutdownVulkan();

	shutdownGlfw();

	//getchar();
	return 0;
}

Well it seems that I finally succeeded in entering the code. However I missed the while(true) in main Loop. Using while(!glfwWindowShouldClose(window)) still throws the exception. Please consider my previous truncated message. I must acknowledge that it was a transcription error on my part that resulted in the initial problem which you corrected . Brotcrunsher is totally without blame for this . His program worked perfectly but remember he used vc2015 libraries. I do not understand why a vc2017 folder is not provided. Surely it is widely adopted now and of course it is the version with the most up to date compiler.
Finally I do wish to commend you for the excellent manner in which you treat questions from beginners such as myself. You are a shining example of how to treat others. Many thanks .

yours sincerely

JOHN


#7

Please Note the initial includes did not copy completely.
they were and

Sorry
JOHN


#8

Do the angle brackets cause a problem ? iostream and vector.


#9

The 2015 libraries work fine with VS2017, I have used them in the past and have double checked again today.

To insert code copy the symbols as you have used the ’ symbol which is different. A quick way would be to copy the entire example below (note I am able to show the symbols below by adding four spaces in front, this is also why some but not all of your code is show with the correct font and a grey background):

```
// Code here.
```

Since you’ve commented out glfwWindowShouldClose(window) your code will never know that the window close button has been pressed, and so will never close.

You need to debug the code, see this tutorial for examples of how to do so. Check that the window value you get from the window creation function is not altered before you pass it to glfwWindowShouldClose.

I will check your code later when I have time. In the meantime I would try to get the basic OpenGL example from the documentation working as you can then use this as a basis to start from after removing OpenGL link settings and adding Vulkan ones.


#10

As a starting point you could use the following code, which creates a no API window and does not require linking to OpenGL32.lib:

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */

	glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

	glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

	window = glfwCreateWindow(1000, 800, "   HELLO VULKAN X86   ", 0, 0);

	if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

#11

Dear Doug,
Thank you for the information that the 2015 libraries work with VC++ 2017. It will take me some time to work through the items that you have suggested.
Yesterday I added the code from Tutorial [023] . After each new line I have included the comment //023. What I find is that glfwCreateWindowSurface is undefined. Perhaps this is useful clue. Let me try to add the complete code as you suggested.


//HELLO VULKAN X86//

#include <iostream>
#include <vector>

//#define GLFW_INCLUDE_VULKAN   //BUILD FAILS

#include<GLFW\glfw3.h>

#define VK_USE_PLATFORM_WIN32_KHR "VK_KHR_Win32_surface"

//#define GLFW_VULKAN_STATIC

#include "vulkan\vulkan.h"     //REQUIRED TO BUILD

void ASSERT_VULKAN(VkResult value)
{
	if (value != VK_SUCCESS) { std::cout << "ASSERT FAILED\n" << value; }
}

void printStats(VkPhysicalDevice &device)
{
	VkPhysicalDeviceProperties properties;
	vkGetPhysicalDeviceProperties(device, &properties);

	uint32_t apiVer = properties.apiVersion;

	std::cout << "\n           HELLO VULKAN X86 PRINT STATS\n\n";
	std::cout << " Name:                      " << properties.deviceName << "\n";
	std::cout << " API Version:               " << properties.apiVersion << "\n";
	std::cout << " Driver Version:            " << properties.driverVersion << "\n";
  	std::cout << " Device ID:                 " << properties.deviceID << "\n";
	std::cout << " Device Type:               " << properties.deviceType << "\n";
	std::cout << " Discrete Queue Priorities: " << properties.limits.discreteQueuePriorities << "\n";

	VkPhysicalDeviceFeatures features;
	vkGetPhysicalDeviceFeatures(device, &features);

	std::cout << " Geometry Shader :          " << features.geometryShader << "\n";
	std::cout << " Tessellation Shader :      " << features.tessellationShader << "\n";

	VkPhysicalDeviceMemoryProperties memProps;

	uint32_t numberofQueueFamilies = 0;
	uint32_t queueCount = 0;


	vkGetPhysicalDeviceMemoryProperties(device, &memProps);
	
	vkGetPhysicalDeviceQueueFamilyProperties(device, &numberofQueueFamilies, nullptr);

	VkQueueFamilyProperties *familyProperties = new VkQueueFamilyProperties[numberofQueueFamilies];  // BETTER USE STD::VECTOR

	vkGetPhysicalDeviceQueueFamilyProperties(device, &numberofQueueFamilies, familyProperties);

	std::cout << " Number of Queue Families:  " << numberofQueueFamilies << "\n";

	for (uint32_t i = 0; i < numberofQueueFamilies; i++)
	{
		std::cout << "\n Queue Family # " << i << " \n";
		std::cout << " VK_QUEUE_GRAPHICS_BIT:        " << ((familyProperties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) << "\n";
		std::cout << " VK_QUEUE_COMPUTE_BIT:         " << ((familyProperties[i].queueFlags & VK_QUEUE_COMPUTE_BIT) != 0) << "\n";
		std::cout << " VK_QUEUE_TRANSFER_BIT:        " << ((familyProperties[i].queueFlags & VK_QUEUE_TRANSFER_BIT) != 0) << "\n";
		std::cout << " VK_QUEUE_SPARSE_BINDING_BIT:  " << ((familyProperties[i].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) != 0) << "\n";
		std::cout << " Queue Count:                  " << familyProperties[i].queueCount << "\n";
		std::cout << " Timestamp Valid Bits:         " << familyProperties[i].timestampValidBits << "\n";

		uint32_t width = familyProperties[i].minImageTransferGranularity.width;

		uint32_t height = familyProperties[i].minImageTransferGranularity.height;

		uint32_t depth = familyProperties[i].minImageTransferGranularity.depth;

		std::cout << " Min Image timestamp Granularity: " << width << ", " << height << ", " << depth << "\n";

   }

	delete[] familyProperties; 
}

VkApplicationInfo appInfo;

VkInstance instance;

VkSurfaceKHR surface; //023

VkDevice device;

GLFWwindow *window;


void startGlfw()
{
	glfwInit();

	glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);

	glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

	window = glfwCreateWindow(1000, 800, "   HELLO VULKAN X86   ", nullptr, nullptr);
}

//int main(int argc, char** argv)

void startVulkan()
{
	//APPLICATION INFO//

	appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
	appInfo.pNext = NULL;
	appInfo.pApplicationName = "VULKAN TUTORIAL";
	appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
	appInfo.pEngineName = "JOHN'S MACHINE";
	appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
	appInfo.apiVersion = VK_API_VERSION_1_0;

	uint32_t numberofLayers = 0;

	vkEnumerateInstanceLayerProperties(&numberofLayers, nullptr);

	VkLayerProperties *layers = new VkLayerProperties[numberofLayers];

	vkEnumerateInstanceLayerProperties(&numberofLayers, layers);

	std::cout << "\n              HELLO VULKAN X86 \n\n DEVICE PROPERTIES\n";

	std::cout << "\n Number of Instance Layers: " << numberofLayers << "\n";

	for (uint32_t i = 0; i < numberofLayers; i++)
	{
		std::cout << " Name:                    " << layers[i].layerName << "\n";
		std::cout << " Spec Version:            " << layers[i].specVersion << "\n";
		std::cout << " Implementation Version:  " << layers[i].implementationVersion << "\n";
		std::cout << " Description:             " << layers[i].description << "\n\n";
	}

	uint32_t numberofExtensions = 0;

	vkEnumerateInstanceExtensionProperties(nullptr, &numberofExtensions, nullptr);

	VkExtensionProperties *extensions = new VkExtensionProperties[numberofExtensions];

	vkEnumerateInstanceExtensionProperties(nullptr, &numberofExtensions, extensions);

	std::cout << "\n Number of Extensions:      " << numberofExtensions << "\n";

	for (uint32_t i = 0; i < numberofExtensions; i++)
	{
		std::cout << " Name:                    " << extensions[i].extensionName << "\n";

		std::cout << " Spec Version:            " << extensions[i].specVersion << "\n";
	}

	const std::vector<const char*> validationLayers = { "VK_LAYER_LUNARG_standard_validation" };

	const std::vector<const char*> usedExtensions = { "VK_KHR_surface", VK_KHR_WIN32_SURFACE_EXTENSION_NAME };

	uint32_t numberofGlfwExtensions = 0;//023

	auto glfwExtensions = glfwGetRequiredInstanceExtensions(&numberofGlfwExtensions);//023

	//INSTANCE INFO//

	VkInstanceCreateInfo instanceInfo;

	instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
	instanceInfo.pNext = nullptr;
	instanceInfo.flags = 0;
	instanceInfo.pApplicationInfo = &appInfo;
	instanceInfo.enabledLayerCount = 0;
	instanceInfo.ppEnabledLayerNames = nullptr;
	instanceInfo.enabledExtensionCount = numberofGlfwExtensions;
	instanceInfo.ppEnabledExtensionNames = usedExtensions.data();

	//INSTANCE CREATION//

	VkResult result = vkCreateInstance(&instanceInfo, nullptr, &instance);// THIS THROWS EXCEPTION FOR LAYER COUNT >0

	ASSERT_VULKAN(result);

	result = glfwCreateWindowSurface(instance, window, nullptr, &surface); //023 GLFWCREATEWINDOWSURFACE UNDEFINED ! 
	
	//ASSERT_VULKAN(result); //023 


	//SURFACE INFO//

	VkWin32SurfaceCreateInfoKHR surfaceCreateInfo;

	surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR;

	surfaceCreateInfo.pNext = nullptr;

	surfaceCreateInfo.flags = 0;

	surfaceCreateInfo.hinstance = nullptr;

	surfaceCreateInfo.hwnd = nullptr;

	ASSERT_VULKAN(result);

	//UNSURE CONCERNING ORDER OF SURFACE AND PROCADDR HERE//

	//VkSurfaceKHR surface;

	result = vkCreateWin32SurfaceKHR(instance, &surfaceCreateInfo, nullptr, &surface);
	ASSERT_VULKAN(result);

	

	vkGetInstanceProcAddr(instance, "");

	uint32_t numberofPhysicalDevices = 0;

	result = vkEnumeratePhysicalDevices(instance, &numberofPhysicalDevices, nullptr);
	ASSERT_VULKAN(result);

	//VkPhysicalDevice *physicalDevices = new VkPhysicalDevice[numberofPhysicalDevices];

	std::vector<VkPhysicalDevice> physicalDevices;

	physicalDevices.resize(numberofPhysicalDevices);

	result = vkEnumeratePhysicalDevices(instance, &numberofPhysicalDevices, physicalDevices.data());
	ASSERT_VULKAN(result);

	for (uint32_t i = 0; i < numberofPhysicalDevices; i++)
	{
		printStats(physicalDevices[i]);
	}

	//QUEUE INFO//

	float queuePriorities[] = { 1.0f, 1.0f, 1.0f, 1.0f };

	VkDeviceQueueCreateInfo deviceQueueCreateInfo;

	deviceQueueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
	deviceQueueCreateInfo.pNext = nullptr;
	deviceQueueCreateInfo.flags = 0;
	deviceQueueCreateInfo.queueFamilyIndex = 0; // TO DO SELECT CORRECT FAMILY INDEX
	deviceQueueCreateInfo.queueCount = 4;       // TO DO CHECK IF THIS IS A VALID NUMBER
	deviceQueueCreateInfo.pQueuePriorities = nullptr;       // TO DO CHECK IF THIS IS A VALID NUMBER

	//PHYSICAL DEVICE//

	VkPhysicalDeviceFeatures usedFeatures = {};

	VkDeviceCreateInfo deviceCreateInfo;

	deviceCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
	deviceCreateInfo.pNext = nullptr;
	deviceCreateInfo.flags = 0;
	deviceCreateInfo.queueCreateInfoCount = 1;
	deviceCreateInfo.pQueueCreateInfos = &deviceQueueCreateInfo;
	deviceCreateInfo.enabledLayerCount = 0;
	deviceCreateInfo.ppEnabledLayerNames = nullptr;
	deviceCreateInfo.enabledExtensionCount = 0;
	deviceCreateInfo.ppEnabledExtensionNames = nullptr;
	deviceCreateInfo.pEnabledFeatures = &usedFeatures;

	result = vkCreateDevice(physicalDevices[0], &deviceCreateInfo, nullptr, &device);
	ASSERT_VULKAN(result);

	VkQueue queue;

	vkGetDeviceQueue(device, 0, 0, &queue);

	vkDeviceWaitIdle(device);

	vkDestroyDevice(device, nullptr);
	vkDestroySurfaceKHR(instance, surface, nullptr);
	vkDestroyInstance(instance, nullptr);


	delete[] layers;

	delete[] extensions;
}



void mainLoop()
{

	while(true)// (!glfwWindowShouldClose(window)) //THIS THROWS EXCEPTION (true) WINDOW PERSISTS BUT CAN'T BE CLOSED
	{		
		glfwPollEvents();
	}
	
}

void shutdownVulkan()
{

	vkDeviceWaitIdle(device);

	vkDestroyDevice(device, nullptr);

	vkDestroySurfaceKHR(instance, surface, nullptr);
	
	vkDestroyInstance(instance, nullptr);


}

void shutdownGlfw()
{
	glfwDestroyWindow(window);
}

int main(int argc, char** argv)
{
	startGlfw();

    startVulkan();

	mainLoop();

	shutdownVulkan();

	shutdownGlfw();

	//getchar();
	return 0;

Although the first two includes are not showing here they are present in my code.

yours sincerely

John


#12

Hi John,

I’ve fixed your formatting by using three ` symbols. You can look at how I did that by editing your post (and cancelling afterwards).

Some questions:

  1. Did you try the example I posted?
  2. As you’ve added code does that mean you no longer have a problem closing the window?

You should look at the documentation from GLFW for using Vulkan and stick as close to example code as possible. You’ll see that in your case you included vulkan after glfw instead of before it. This is stated in the documentation: Unless a Vulkan header is included, either by the GLFW header or above it, any GLFW functions that take or return Vulkan types will not be declared.

You should have:

#include "vulkan\vulkan.h" // put this before including glfw
#include<GLFW\glfw3.h>

You should now be able to compile with glfwCreateWindowSurface calls.

Good luck!