Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when failed to load a texture. #37

Open
syoyo opened this issue Feb 4, 2020 · 3 comments
Open

Segmentation fault when failed to load a texture. #37

syoyo opened this issue Feb 4, 2020 · 3 comments

Comments

@syoyo
Copy link
Contributor

syoyo commented Feb 4, 2020

https://github.com/SaschaWillems/Vulkan-glTF-PBR/blob/master/base/VulkanTexture.hpp#L89

Creating gli::texture2d or gli::texture_cube directly from gli::load triggers assertion(debug build) or gives undefined behaviour(usually this results to a Vulkan error) in the constructor when failed to load a texture file.
(It does not create empty gli texture)

Here is an example when failed to load a texture.

Fatal : VkResult is "-2" in /mnt/data/work/Vulkan-glTF-PBR/base/VulkanglTFModel.hpp at line 184
Vulkan-glTF-PBR: /mnt/data/work/Vulkan-glTF-PBR/base/VulkanglTFModel.hpp:184: void vkglTF::Texture::fromglTfImage(tinygltf::Image&, vkglTF::TextureSampler, vks::VulkanDevice*, VkQueue): Assertion `res == VK_SUCCESS' failed.
Aborted (core dumped)

Tthis is an issue of gli, so it should be fixed in gli library. For a while, we can use the following workaround:

  gli::texture tex(gli::load(filename.c_str());
  // will create empty texture when failed to load a texture.

  if (!tex.empty()) {
    // trigger assertion or return false
  }
  gli::texture2d tex2D(tex);

  ...

Related to: https://github.com/g-truc/gli/issues/174

@SaschaWillems
Copy link
Owner

Thanks for reporting this. I'll take a look into this.

@SaschaWillems
Copy link
Owner

As with my Vulkan samples, I'll replace gli with libktx. This gives more control over how to handle texture loading failures.

What would be your favorite way of handling texture loading failures? Right now the ktx loading will also just assert, and I think showing some kind of message or gracefully exiting with a proper output would be sufficient.

@syoyo
Copy link
Contributor Author

syoyo commented Feb 20, 2020

I'll replace gli with libktx

Awesome!

What would be your favorite way of handling texture loading failures?

Less assertion as much as possible(so we may better to check if a texture file exists before libktx API call). Simply print an error when failed to load a texture(and/or file not found), then exit an app is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants