From 6fe10e88097a1669433a79609e94259bfc46b029 Mon Sep 17 00:00:00 2001 From: halx99 Date: Tue, 25 Aug 2020 23:12:26 +0800 Subject: [PATCH] Add utils::killCurrentProcess API to kill game immidiately --- cocos/base/ccUtils.cpp | 16 ++++++++++++++++ cocos/base/ccUtils.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index 03818796b7..d39282e446 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -2,6 +2,7 @@ Copyright (c) 2010 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2020 c4games.com http://www.cocos2d-x.org @@ -28,6 +29,14 @@ THE SOFTWARE. #include #include + +#if !defined(_WIN32) +// for unix/linux kill +#include +#include +#include +#endif + #include "md5/md5.h" #include "base/CCDirector.h" @@ -721,6 +730,13 @@ std::string bin2hex(const std::string& binary /*charstring also regard as binary return result; } +void killCurrentProcess() +{ +#if !defined(_WIN32) + ::kill(::getpid(), SIGKILL); +#endif +} + } NS_CC_END diff --git a/cocos/base/ccUtils.h b/cocos/base/ccUtils.h index e7fbe7a524..68a3c62e4c 100644 --- a/cocos/base/ccUtils.h +++ b/cocos/base/ccUtils.h @@ -2,6 +2,7 @@ Copyright (c) 2010 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +Copyright (c) 2020 c4games.com http://www.cocos2d-x.org @@ -258,6 +259,14 @@ namespace utils * @lua NA */ CC_DLL std::string bin2hex(const std::string& binary /*charstring also regard as binary in C/C++*/, int delim = -1, bool prefix = false); + + /** + @brief killCurrentProcess immidiately, any object's destructor never call + @return NA. + * @js NA + * @lua NA + */ + CC_DLL void killCurrentProcess(); } NS_CC_END