diff --git a/ops.cc b/ops.cc index c54ad12..2588ea4 100644 --- a/ops.cc +++ b/ops.cc @@ -242,6 +242,26 @@ T_OpContext::T_OpContext( } } +namespace { +struct T_RunGuard +{ + T_OpContext& context; + T_RunGuard( T_OpContext& ctx ) noexcept : context( ctx ) {} + + ~T_RunGuard( ) + { + while ( !context.profiling.empty( ) ) { + Globals::Profiler( ).end( context.profiling.last( ) ); + context.profiling.removeLast( ); + } + glUseProgram( 0 ); + glBindProgramPipeline( 0 ); + glBindFramebuffer( GL_FRAMEBUFFER , 0 ); + Globals::Textures( ).reset( ); + } +}; +} + void T_OpContext::run( const E_RunTarget target , const float time , @@ -249,6 +269,8 @@ void T_OpContext::run( const float height ) { assert( !aborted ); + + T_RunGuard rg( *this ); x87sp = 0; instrPtr = program.ops.firstOf( target == R_INIT ? program.init : program.frame ); values[ 0 ] = time;