1
0
forked from 0ad/0ad

Shutdown mongoose in rl-interface gracefully

When the `RL::Interface` is destroied but the engine isn't completely
shoutdown there was a dangling pointer. The time the dangling pointer is
accessable got expanded with 968e55704a.
Whith this patch there no dangling pointer (in that regard).

Accepted by: @vladislavbelov
Comments by: @Stan, @sera
Trac Tickets: #5989

Differential Revision: https://code.wildfiregames.com/D5254
This was SVN commit r28123.
This commit is contained in:
phosit 2024-06-23 17:26:03 +00:00
parent e8908dfee8
commit fa1dc98103
2 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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;
};
}