From e8c9cee3bcfb7f5124389bdb528e4fcd5c6619cd Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 16 Dec 2021 21:30:46 +0000 Subject: [PATCH] Fixed infinite error hook loop Bumped revision number --- source/main.cpp | 4 ++-- source/shared.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 96f23a6..347749c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -12,11 +12,11 @@ GMOD_MODULE_OPEN( ) { LUA->CreateTable( ); - LUA->PushString( "luaerror 1.5.6" ); + LUA->PushString( "luaerror 1.5.7" ); LUA->SetField( -2, "Version" ); // version num follows LuaJIT style, xxyyzz - LUA->PushNumber( 10506 ); + LUA->PushNumber( 10507 ); LUA->SetField( -2, "VersionNum" ); #if defined LUAERROR_SERVER diff --git a/source/shared.cpp b/source/shared.cpp index f571f78..9804f7c 100644 --- a/source/shared.cpp +++ b/source/shared.cpp @@ -270,6 +270,9 @@ class CLuaGameCallback : public GarrysMod::Lua::ILuaGameCallback void LuaError( const CLuaError *error ) { + if( entered_hook ) + return callback->LuaError( error ); + const int32_t funcs = LuaHelpers::PushHookRun( lua, "LuaError" ); if( funcs == 0 ) return callback->LuaError( error ); @@ -306,7 +309,10 @@ class CLuaGameCallback : public GarrysMod::Lua::ILuaGameCallback lua->PushString( std::to_string( source_addon->wsid ).c_str( ) ); } - if( !LuaHelpers::CallHookRun( lua, 4 + args, 1 ) ) + entered_hook = true; + const bool call_success = LuaHelpers::CallHookRun( lua, 4 + args, 1 ); + entered_hook = false; + if( !call_success ) return callback->LuaError( error ); const bool proceed = !lua->IsType( -1, GarrysMod::Lua::Type::BOOL ) || !lua->GetBool( -1 ); @@ -339,6 +345,7 @@ class CLuaGameCallback : public GarrysMod::Lua::ILuaGameCallback private: GarrysMod::Lua::CLuaInterface *lua; GarrysMod::Lua::ILuaGameCallback *callback; + bool entered_hook = false; }; static CLuaGameCallback callback;