From 8d5cafecb39c12522c8c8534d9acf708599c3d13 Mon Sep 17 00:00:00 2001 From: melex750 Date: Sat, 15 Aug 2020 09:41:31 -0400 Subject: [PATCH] Fix CBOT script hanging at delete() --- src/script/scriptfunc.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp index e4d36b0d..7f09ed5e 100644 --- a/src/script/scriptfunc.cpp +++ b/src/script/scriptfunc.cpp @@ -734,6 +734,9 @@ bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, vo } else { + CScript* script = static_cast(user); + bool deleteSelf = (obj == script->m_object); + if ( exploType != DestructionType::NoEffect && obj->Implements(ObjectInterfaceType::Destroyable) ) { dynamic_cast(obj)->DestroyObject(static_cast(exploType)); @@ -752,12 +755,13 @@ bool CScriptFunctions::rDelete(CBotVar* var, CBotVar* result, int& exception, vo } CObjectManager::GetInstancePointer()->DeleteObject(obj); } + // Returning "false" here makes sure the program doesn't try to keep executing + // if the robot just destroyed itself using delete(this.id) + // See issue #925 + return !deleteSelf; } - // Returning "false" here makes sure the program doesn't try to keep executing if the robot just destroyed itself - // using delete(this.id) - // See issue #925 - return false; + return true; } static CBotTypResult compileSearch(CBotVar* &var, void* user, CBotTypResult returnValue)