1
0
forked from 0ad/0ad

MapGenerator to delete its ScriptInterface directly after last use, refs 64efbfeae3, D2085.

Differential Revision: https://code.wildfiregames.com/D2084
Reviewed By: historic_bruno
This was SVN commit r22489.
This commit is contained in:
elexis 2019-07-17 00:07:10 +00:00
parent f41e4082d9
commit e8f4ae36a7

View File

@ -105,6 +105,8 @@ void* CMapGeneratorWorker::RunThread(void *data)
self->m_Progress = -1;
}
SAFE_DELETE(self->m_ScriptInterface);
// At this point the random map scripts are done running, so the thread has no further purpose
// and can die. The data will be stored in m_MapData already if successful, or m_Progress
// will contain an error value on failure.
@ -114,15 +116,6 @@ void* CMapGeneratorWorker::RunThread(void *data)
bool CMapGeneratorWorker::Run()
{
// We must destroy the ScriptInterface in the same thread because the JSAPI requires that!
// Also we must not be in a request when calling the ScriptInterface destructor, so the autoFree object
// must be instantiated before the request (destructors are called in reverse order of instantiation)
struct AutoFree {
AutoFree(ScriptInterface* p) : m_p(p) {}
~AutoFree() { SAFE_DELETE(m_p); }
ScriptInterface* m_p;
} autoFree(m_ScriptInterface);
JSContext* cx = m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);