[Bug report] Segmentation fault when using includer interface on MSVC
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 445
- Avg merge
- 11h 6m
- Merged PRs (30d)
- 6
Description
There seems to be a bug with shaderc on windows.
If you try to use the `IncluderInterface` object trying to access the `GetInclude` function will throw an segmentation fault.
This is the shortest code I could come up with that produces this error:
```
/** @cond */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/** @endcond */
#include "shaderc/shaderc.hpp"
using namespace shaderc;
using namespace std;
namespace fs = std::filesystem;
string source =
"#version 450\n"
"#extension GL_ARB_separate_shader_objects : enable\n"
"#extension GL_GOOGLE_include_directive : require\n"
"\n"
"#include \n"
"\n"
"layout(location = 0) out vec4 color_out;\n"
"\n"
"layout(location = 0) in vec3 position;\n"
"layout(location = 1) in vec2 tex_coord;\n"
"layout(location = 2) in vec3 normal;\n"
"\n"
"layout(binding = 1) uniform CameraInfo {\n"
" vec3 camera_position;\n"
"};\n"
"\n"
"void main()\n"
"{\n"
" color_out = BlinnPhong(\n"
" position,\n"
" normal,\n"
" camera_position,\n"
" vec3(0, 0, 1),\n"
" vec3(1),\n"
" normalize(vec3(1, 1, 1)) * 0.3,\n"
" 100);\n"
"}\n";
// This class is designed to be very short lived, do not cache it.
class NEShaderIncluder : public CompileOptions::IncluderInterface
{
std::string name;
std::string content;
shaderc_include_result result;
shaderc_include_type mtype;
public:
NEShaderIncluder()
{
cout << "constructed" << endl;
}
shaderc_include_result* GetInclude(
const char* requested_source,
shaderc_include_type type,
const char* requesting_source,
size_t include_depth) override
{
cout << "included" << endl;
return &result;
};
void ReleaseInclude(shaderc_include_result* data) override {}
};
int main()
{
const string phong_shader_frag = source;
// Compile from GLSL to spirv.
Compiler compiler = {};
CompileOptions options = {};
options.SetIncluder(std::make_unique());
options.SetGenerateDebugInfo();
shaderc::PreprocessedSourceCompilationResult pre_result =
compiler.PreprocessGlsl(phong_shader_frag, shaderc_shader_kind::shaderc_vertex_shader, "shaders/Example2/phong_shader.frag", options);
return EXIT_SUCCESS;
}
```
I am on Windows 10, compiling with MSVC version 17.
The exact error occurs here:
```
void SetIncluder(std::unique_ptr&& includer) {
includer_ = std::move(includer);
shaderc_compile_options_set_include_callbacks(
options_,
[](void* user_data, const char* requested_source, int type,
const char* requesting_source, size_t include_depth) {
auto* sub_includer = static_cast(user_data);
return sub_includer->GetInclude(
requested_source, static_cast(type),
requesting_source, include_depth);
},
[](void* user_data, shaderc_include_result* include_result) {
auto* sub_includer = static_cast(user_data);
return sub_includer->ReleaseInclude(include_result);
},
includer_.get());
}
```
I am using shaderc version `2021.1` as downloaded by conan.
Contributor guide
Assessment
This issue has not been assessed yet.