You are browsing as a guest. Sign up (or log in) to start making projects!

2h 36m 49s logged

the OpenGL State Machine Strikes Back…

I spent the entire day trapped in hell: debugging a corrupted OpenGL state…

it may not show up as tracked hours.. since most of it was just staring at various forms of text.. but it was painful.

problem

so since i turned the lightmap to run on gpu .. well… Whenever I transitioned from the editor (MapEditState) into Play mode, the map would turn into like a bunch of weird diamonds, and the corruption would persist indefinitely until I remounted the current project.

because it only happened on state transition, i spent hours chasing ghosts in my state management code and scene cleanup routines…

(in the end though i did make some changes to the cleanup routines, but between states rather than scenes.. so i guess i was halfway there?)

the culprit

It was the lighting pass…

took me forever to figure it out, but i had the genius and definitely NOT a very late and obvious idea i shouldve had hours ago, to see if the issue happened when i turned off the lighting system.
so i put some early returns in my lighting system functions and.. it didnt corrupt..

inside LightingSystem::Update(), the renderer was modifying global OpenGL state changing depth functions, blending modes, and texture bindings, but not restoring them to their original defaults properly

When the engine swapped states, the next frame inherited this dirty, half configured state, causing the whole thing to become a mess.

the fix

I went through the lighting system and made sure the state changes are wrapped and properly restored through the render thread..

  • LightingSystem.h: Full GL state save/restore around the light pass. now explicitly backing up and restoring the FBO, program, VAO, blend state, draw buffers, clear color, viewport, and active texture.
  • MapEditState.cpp: OnExit() now properly nulls out m_MapComp and m_CurrentGrid. OnEnter() and will refetch them from the current registry so it isnt holding onto outdated references.
  • EditorLayer.cpp: Added a call to renderer->Clean() after state transfers to clear out stale VAO and mesh caches.(bc its multithreaded things go kinda weird but.. it works now)

glad thats over with :D


Also heres a fun peek of what ObSL can do with EngineLib, yes, it can make your entire map look like hell..!

i am totally not going insane

0
34

Comments 0

No comments yet. Be the first!