Crash in surfaceless platform due to exception thrown in destructor
Description
When running GLES2 CTS tests on the surfaceless platform (-DDEQP_TARGET=surfaceless), the test runner crashes with std::terminate at specific vertex array test cases.
Based on git commit point 659a0ddba0c1cb5be3f1d52095fae9c4c1d5900a
Steps to Reproduce
- Build VK-GL-CTS with surfaceless target:
mkdir build && cd build
cmake .. -DDEQP_TARGET=surfaceless -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc) deqp-gles2
- Run the test:
./modules/gles2/deqp-gles2 --deqp-surface-type=fbo --deqp-surface-width=256 --deqp-surface-height=256 --deqp-archive-dir="../data"
- The test case crash at:
Test case 'dEQP-GLES2.functional.vertex_arrays.single_attribute.strides.buffer_0_8_float2_vec4_dynamic_draw_quads_1'..
terminate called after throwing an instance of 'glu::Error'
what(): glDeleteBuffers(): glGetError() returned GL_INVALID_OPERATION at glsVertexArrayTests.cpp:411
IOT instruction (core dumped)
Full log file: log.txt
Root Cause Analysis
The crash occurs in ContextArray::~ContextArray() at modules/glshared/glsVertexArrayTests.cpp:411:
ContextArray::~ContextArray(void)
{
if (m_storage == STORAGE_BUFFER)
{
m_ctx.deleteBuffers(1, &m_glBuffer);
GLU_EXPECT_NO_ERROR(m_ctx.getError(), "glDeleteBuffers()"); // Line 411
}
// ...
}
The issue is:
On surfaceless platform, the GL context may become invalid during test cleanup/teardown
glDeleteBuffers() returns GL_INVALID_OPERATION when called without a valid context
GLU_EXPECT_NO_ERROR throws a glu::Error exception
Throwing an exception in a destructor causes std::terminate() to be called (especially during stack unwinding)
This violates C++ best practices - destructors should never throw exceptions, as they are implicitly noexcept since C++11.