Skip to content

OpenGL crashes after allocating as many render buffers as the first UBO index #566

@adriengivry

Description

@adriengivry

Description

Every object generated with OpenGL has a unique ID.
However, 2 different object types can share the same IDs.
For instance, generating many "regular buffers", like UBOs, VBOs, etc... will increment the ID by 1 every time. But when creating a renderbuffer (RBO), it will start at 1 again (meaning a UBO and a RBO can have the same index). When this happens, and some code tries to bind/use the UBO it seems like OpenGL enters an invalid state and can basically crash at any time.

[ERROR] 2025-05-27_23-37-28 OpenGL Debug Message:
Debug message (1282): GL_INVALID_OPERATION error generated. <buffer> does not refer to an existing buffer object.
Source: API
Type: Error
Severity: High
[ERROR] 2025-05-27_23-37-28 OpenGL Debug Message:
Debug message (1282): GL_INVALID_OPERATION error generated. Buffer name does not refer to an buffer object generated by OpenGL.
Source: API
Type: Error
Severity: High

To Reproduce

Steps to reproduce the behavior:

  1. Add this code anywhere in the editor, for instance in OvEditor::Core::Editor::HandleGlobalShortcuts():
if (m_context.inputManager->IsKeyPressed(OvWindowing::Inputs::EKey::KEY_X))
{
	auto renderbuffer = std::make_unique<OvRendering::HAL::GLRenderbuffer>();
	OVLOG_INFO(std::format("Render Buffer Created with ID: {}", renderbuffer->GetID()));
}
  1. Launch the editor
  2. Press X until ID ~30-40
  3. Notice the issue

Expected behavior

It shouldn't matter if an RBO and a UBO have the same ID?

Callstack

OvEditor.exe!`anonymous namespace'::GLDebugMessageCallback(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char * message, const void * userParam) Line 29	C++
[External Code]	
OvEditor.exe!OvRendering::HAL::TBuffer<1,OvRendering::HAL::GLBufferContext>::Upload(const void * p_data, std::optional<OvRendering::HAL::BufferMemoryRange> p_range) Line 41	C++
OvEditor.exe!OvCore::Rendering::EngineBufferRenderFeature::OnBeginFrame(const OvRendering::Data::FrameDescriptor & p_frameDescriptor) Line 70	C++
OvEditor.exe!OvRendering::Core::CompositeRenderer::BeginFrame(const OvRendering::Data::FrameDescriptor & p_frameDescriptor) Line 30	C++
OvEditor.exe!OvCore::Rendering::SceneRenderer::BeginFrame(const OvRendering::Data::FrameDescriptor & p_frameDescriptor) Line 171	C++
OvEditor.exe!OvEditor::Panels::AView::Render() Line 76	C++
OvEditor.exe!OvEditor::Core::Editor::RenderViews(float p_deltaTime) Line 253	C++
OvEditor.exe!OvEditor::Core::Editor::Update(float p_deltaTime) Line 101	C++
OvEditor.exe!OvEditor::Core::Application::Run() Line 30	C++
OvEditor.exe!`anonymous namespace'::TryRun(const std::filesystem::path & projectPath) Line 60	C++
OvEditor.exe!main(int argc, char * * argv) Line 103	C++

Screenshots

OvEditor_kMKRy4tv3u.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    CrashSomething that causes a crashCriticalSomething that should be fixed quicklyGraphicsGraphical feature

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions