diff --git a/src/ai/ai_scanner.cpp b/src/ai/ai_scanner.cpp index 281b8925d3..1c7b089470 100644 --- a/src/ai/ai_scanner.cpp +++ b/src/ai/ai_scanner.cpp @@ -32,7 +32,7 @@ void AIScannerInfo::Initialize() { ScriptScanner::Initialize("AIScanner"); - ScriptAllocatorScope alloc_scope(this->engine); + ScriptAllocatorScope alloc_scope(this->engine.get()); /* Create the dummy AI */ this->main_script = "%_dummy"; diff --git a/src/script/script_scanner.cpp b/src/script/script_scanner.cpp index 0aea257240..102ce454d4 100644 --- a/src/script/script_scanner.cpp +++ b/src/script/script_scanner.cpp @@ -44,10 +44,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t, const std::stri return true; } -ScriptScanner::ScriptScanner() : - engine(nullptr) -{ -} +ScriptScanner::ScriptScanner() = default; void ScriptScanner::ResetEngine() { @@ -58,7 +55,7 @@ void ScriptScanner::ResetEngine() void ScriptScanner::Initialize(std::string_view name) { - this->engine = new Squirrel(name); + this->engine = std::make_unique(name); this->RescanDir(); @@ -68,8 +65,6 @@ void ScriptScanner::Initialize(std::string_view name) ScriptScanner::~ScriptScanner() { this->Reset(); - - delete this->engine; } void ScriptScanner::RescanDir() diff --git a/src/script/script_scanner.hpp b/src/script/script_scanner.hpp index e05da0b2ba..e70ffe7b0b 100644 --- a/src/script/script_scanner.hpp +++ b/src/script/script_scanner.hpp @@ -26,7 +26,7 @@ public: /** * Get the engine of the main squirrel handler (it indexes all available scripts). */ - class Squirrel *GetEngine() { return this->engine; } + class Squirrel *GetEngine() { return this->engine.get(); } /** * Get the current main script the ScanDir is currently tracking. @@ -84,7 +84,7 @@ public: void RescanDir(); protected: - class Squirrel *engine; ///< The engine we're scanning with. + std::unique_ptr engine; ///< The engine we're scanning with. std::string main_script; ///< The full path of the script. std::string tar_file; ///< If, which tar file the script was in.