Resolved #2 (Выгрузка домена ресурса крашит сервер при следующем запуске)

This commit is contained in:
Kernell 2015-12-06 10:32:56 +03:00
parent 53f257eb13
commit 0c54eb7c2a
5 changed files with 48 additions and 15 deletions

View File

@ -46,7 +46,7 @@ CMonoDomain::~CMonoDomain( void )
MonoObject *pException = nullptr;
//mono_domain_try_unload( this->m_pDomain, &pException );
mono_domain_try_unload( this->m_pDomain, &pException );
this->HandleException( pException );
}

View File

@ -13,6 +13,8 @@
#include "CMonoInterface.h"
#include "CMonoFunctions.h"
MonoAssembly* CMonoInterface::m_pMTALib = nullptr;
CMonoInterface::CMonoInterface( void )
{
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" );
@ -21,10 +23,19 @@ CMonoInterface::CMonoInterface( void )
mono_debug_init( MONO_DEBUG_FORMAT_MONO );
mono_trace_set_level_string( "error" );
#if _DEBUG
mono_trace_set_level_string( "debug" );
#else
mono_trace_set_level_string( "critical" );
#endif
mono_trace_set_print_handler( CMonoInterface::MonoPrintCallbackHandler );
mono_trace_set_printerr_handler( CMonoInterface::MonoPrintErrorCallbackHandler );
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );
CMonoInterface::m_pMTALib = mono_assembly_open_full( "mods/deathmatch/mono/lib/MultiTheftAuto.dll", nullptr, FALSE );
CMonoFunctions::AddInternals();
this->m_pGC = new CMonoGC;
@ -223,4 +234,19 @@ CLuaArguments CMonoInterface::MonoArrayToLuaArguments( MonoArray* pArray )
}
return pLuaArguments;
}
}
MonoAssembly* CMonoInterface::GetMTALib( void )
{
return CMonoInterface::m_pMTALib;
}
void CMonoInterface::MonoPrintCallbackHandler( const char *string, mono_bool is_stdout )
{
g_pModuleManager->Printf( string );
}
void CMonoInterface::MonoPrintErrorCallbackHandler( const char *string, mono_bool is_stdout )
{
g_pModuleManager->ErrorPrintf( string );
}

View File

@ -24,29 +24,36 @@ class CMonoInterface;
class CMonoInterface
{
private:
MonoDomain* m_pMonoDomain;
MonoDomain* m_pMonoDomain;
CMonoGC* m_pGC;
CMonoGC* m_pGC;
static MonoAssembly* m_pMTALib;
public:
CMonoInterface ( void );
~CMonoInterface ( void );
CMonoInterface ( void );
~CMonoInterface ( void );
CMonoDomain* CreateAppdomain ( CResource* pResource, const char* szName, char* szConfig );
CMonoDomain* CreateAppdomain ( CResource* pResource, const char* szName, char* szConfig );
void SetDomain ( MonoDomain* pDomain = nullptr, bool bForce = false );
void SetDomain ( MonoDomain* pDomain = nullptr, bool bForce = false );
CMonoGC* GetGC ( void ) { return this->m_pGC; }
CMonoGC* GetGC ( void ) { return this->m_pGC; }
#pragma region Static methods
static string GetBinariesDirectory( void )
static string GetBinariesDirectory( void )
{
return "mods/deathmatch/resources/[ire]";
}
static MonoAssembly* GetMTALib( void );
static CLuaArguments MonoArrayToLuaArguments( MonoArray* pArray );
static void MonoPrintCallbackHandler( const char *string, mono_bool is_stdout );
static void MonoPrintErrorCallbackHandler( const char *string, mono_bool is_stdout );
#pragma endregion
};

View File

@ -21,9 +21,7 @@ CMonoMTALib::CMonoMTALib( CMonoDomain* pDomain )
this->m_pImage = nullptr;
this->m_pDomain = pDomain;
string strPath( CMonoInterface::GetBinariesDirectory() + "/" + pDomain->GetResource()->GetName() + "/MultiTheftAuto.dll" );
this->m_pAssembly = pDomain->OpenAssembly( strPath.c_str() );
this->m_pAssembly = CMonoInterface::GetMTALib();
if( this->m_pAssembly )
{

View File

@ -32,12 +32,14 @@ CResource::~CResource( void )
g_pResourceManager->RemoveFromList( this );
SAFE_DELETE( this->m_pEventManager );
SAFE_DELETE( this->m_pMonoDomain );
this->GetMono()->SetDomain( nullptr, true );
SAFE_DELETE( this->m_pMonoDomain );
this->m_pMono = nullptr;
this->m_pLuaVM = nullptr;
}
bool CResource::CallEvent( string strEventName, void* pThis, list< CLuaArgument* > argv )