Problems while activating layers

Hey,
At the moment I begin to develop my first application that uses Vulkan.
But I’m getting trouble while activating a layer. Before i tryied to activate a layer i uses this code:

instanceCreateInfo.enabledLayerCount = 0;
instanceCreateInfo.ppEnabledLayerNames = NULL;

But now I would like to activate the Layer “VK_LAYER_LUNARG_standard_validation”.
This would i do with that code: std::vector<const char*> enabledInstanceLayers;

enabledInstanceLayers.push_back("VK_LAYER_LUNARG_standard_validation");
instanceCreateInfo.enabledLayerCount = static_cast<uint32_t>(1);
instanceCreateInfo.ppEnabledLayerNames = &enabledInstanceLayers[0];

But while performing this code I get an Exception where I create the Instance:
VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);

It says something like access to injury while reading at position 0x2E312E31.
Can someone help me with this error? I’ve tried to activate the layers with this Tutorial:
https://gpuopen.com/using-the-vulkan-validation-layers/”.

Not an answer, but a congratulations on being the first person to create a new topic on the new forums! :slight_smile:

Hey Fawkes!

I’ve tried to create an instance with only that layer and it worked. Could you show us a little bit more of your code?

I have a function created fpr the ApplicationInfo and the InstanceCreateInfo.

These function I call with that code:

VkApplicationInfo appInfo = createApplicationInfo(appName, engineName, 0, 0, 1);
VkInstanceCreateInfo instanceCreateInfo = createInstanceCreateInfo(appInfo);

The Instance I create with:

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

Here the method which create the ApplicationInfo:

VkApplicationInfo Engine::createApplicationInfo(const char appName[], const char engineName[], short major, short minor, short patch)
{
	VkApplicationInfo appInfo;
	appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
	appInfo.pNext = NULL;
	
	appInfo.pApplicationName = appName;
	appInfo.applicationVersion = VK_MAKE_VERSION(static_cast<int>(major), static_cast<int>(minor),      static_cast<int>(patch));
	appInfo.pEngineName = engineName;
	appInfo.engineVersion = VK_MAKE_VERSION(0, 0, 1);
	appInfo.apiVersion = VK_API_VERSION_1_0;
	return appInfo;
}

Here is the function for creating the InstanceCreateInfo, maybe this part of the code is more important.

VkInstanceCreateInfo Engine::createInstanceCreateInfo(VkApplicationInfo &appInfo)
{
	VkInstanceCreateInfo instanceCreateInfo;
	instanceCreateInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
	instanceCreateInfo.pNext = NULL;
	instanceCreateInfo.flags = 0;
	instanceCreateInfo.pApplicationInfo = &appInfo;
	//Extensions set for Instance
	instanceCreateInfo.ppEnabledExtensionNames = NULL;
	instanceCreateInfo.enabledExtensionCount = 0;
//Layer reading
uint32_t amountOfLayers = 0;
	vkEnumerateInstanceLayerProperties(&amountOfLayers, NULL);
	VkLayerProperties *layers = new VkLayerProperties[amountOfLayers];
	vkEnumerateInstanceLayerProperties(&amountOfLayers, layers);
	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;
	}

//Layer übergeben
	std::vector<const char*> enabledInstanceLayers;

	enabledInstanceLayers.push_back("VK_LAYER_LUNARG_standard_validation");
	instanceCreateInfo.enabledLayerCount = static_cast<uint32_t>(1);
	instanceCreateInfo.ppEnabledLayerNames = &enabledInstanceLayers[0];
return instanceCreateInfo;
}

This is the complete code for creating an instance. The error happens at the line where I create the instance:

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

I hope someone could help me how to fix the problem…

    std::vector<const char*> enabledInstanceLayers;
    enabledInstanceLayers.push_back("VK_LAYER_LUNARG_standard_validation");
    instanceCreateInfo.enabledLayerCount = static_cast<uint32_t>(1);
    instanceCreateInfo.ppEnabledLayerNames = &enabledInstanceLayers[0];
    
    return instanceCreateInfo;

Here’s the problem. The vector allocates the strings on the heap, instanceCreateInfo points to these strings but they are freed after the return. So instanceCreateInfo points to freed memory which causes a memory read error.

The new forums have a SOLVED feature. @Fawkes if this resolves your issue, please mark it as resolved. If your question is not resolved, let the thread know. Thanks.

I’m sorry but I didn’t find the SOLVED feature.
Also I don’t develope the total day on my project.
But yes, the post from Charlemagne has solved my issue… Thanks for this :slight_smile:

1 Like

Apparently I misspoke. Users need to have been around a little longer before they can see the Solved button. Any moderator can mark a post as solved if asked. I’ll mark yours as solved.

1 Like