From 8a0afc345f1b1f49a91346fd5b00800a32472a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Tue, 14 Nov 2017 17:46:45 +0100 Subject: [PATCH] Control - Run guard --- ops.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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;