matus-chochlik / oglplus

OGLplus is a collection of open-source, cross-platform libraries which implement an object-oriented facade over the OpenGL® (version 3 and higher) and also OpenAL® (version 1.1) and EGL (version 1.4) C-language APIs. It provides wrappers which automate resource and object management and make the use of these libraries in C++ safer and more convenient.
http://oglplus.org/
Boost Software License 1.0
492 stars 72 forks source link

Program::Build not catchable on error? #142

Open thegrb93 opened 6 years ago

thegrb93 commented 6 years ago

I have a program with a shader that fails to compile, but when I try to catch the CompileError, it is uncatchable. I just get terminate called after throwing an instance of 'oglplus::ObjectError' what(): OpenGL numeric argument out of range.

try
{
    std::cout << "Test1\n";
    //throw std::runtime_error("");
    prog.Build();
    std::cout << "Test2\n";
}
catch(oglplus::CompileError err)
{
    std::cout << "Test3\n";
    std::cout << prog.GetInfoLog() << std::endl;
}
catch(...)
{
    std::cout << "Test4\n";
}

try{
    prog.Use();
}
catch(...)
{
    std::cout << "Test5\n";
    return;
}

With this code, 'Test1' is printed and then the terminate message and the program terminates.

If I uncomment the 'throw' then I get Test1 Test4 Test5

thegrb93 commented 6 years ago

I found out that it's because program.Build builds the shaders with shader.Compile(std::nothrow). If I compile the shaders myself, I think it should work

thegrb93 commented 6 years ago

Yeah, it works when I do

try
{fs.Compile();}
catch(oglplus::CompileError)
{
    std::cout << fs.GetInfoLog() << std::endl;
    return;
}
thegrb93 commented 6 years ago

Same thing happens with prog.Build when it tries to link. I've replaced prog.Build with this and it works now.

try
{vs.Compile();}
catch(oglplus::CompileError)
{
    std::cout << vs.GetInfoLog() << std::endl;
    return;
}
try
{fs.Compile();}
catch(oglplus::CompileError)
{
    std::cout << fs.GetInfoLog() << std::endl;
    return;
}
try
{prog.Link();}
catch(oglplus::LinkError)
{
    std::cout << prog.GetInfoLog() << std::endl;
    return;
}