diff --git a/source/rlinterface/RLInterface.cpp b/source/rlinterface/RLInterface.cpp index bd449c9a75..2a7f7a1510 100644 --- a/source/rlinterface/RLInterface.cpp +++ b/source/rlinterface/RLInterface.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -40,7 +40,7 @@ namespace RL { -Interface::Interface(const char* server_address) : m_GameMessage({GameMessageType::None}) +Interface::Interface(const char* server_address) { LOGMESSAGERENDER("Starting RL interface HTTP server"); @@ -49,8 +49,13 @@ Interface::Interface(const char* server_address) : m_GameMessage({GameMessageTyp "num_threads", "1", nullptr }; - mg_context* mgContext = mg_start(MgCallback, this, options); - ENSURE(mgContext); + m_Context = mg_start(MgCallback, this, options); + ENSURE(m_Context); +} + +Interface::~Interface() +{ + mg_stop(m_Context); } // Interactions with the game engine (g_Game) must be done in the main diff --git a/source/rlinterface/RLInterface.h b/source/rlinterface/RLInterface.h index adbc836a12..ef93885d99 100644 --- a/source/rlinterface/RLInterface.h +++ b/source/rlinterface/RLInterface.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 Wildfire Games. +/* Copyright (C) 2024 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -84,6 +84,7 @@ class Interface NONCOPYABLE(Interface); public: Interface(const char* server_address); + ~Interface(); /** * Non-blocking call to process any pending messages from the RL client. @@ -149,7 +150,7 @@ private: std::string GetGameState() const; private: - GameMessage m_GameMessage; + GameMessage m_GameMessage{GameMessageType::None}; ScenarioConfig m_ScenarioConfig; std::string m_ReturnValue; bool m_NeedsGameState = false; @@ -158,6 +159,8 @@ private: std::mutex m_MsgLock; std::condition_variable m_MsgApplied; std::string m_Code; + + mg_context* m_Context; }; }