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; MonoObject *pException = nullptr;
//mono_domain_try_unload( this->m_pDomain, &pException ); mono_domain_try_unload( this->m_pDomain, &pException );
this->HandleException( pException ); this->HandleException( pException );
} }

View File

@ -13,6 +13,8 @@
#include "CMonoInterface.h" #include "CMonoInterface.h"
#include "CMonoFunctions.h" #include "CMonoFunctions.h"
MonoAssembly* CMonoInterface::m_pMTALib = nullptr;
CMonoInterface::CMonoInterface( void ) CMonoInterface::CMonoInterface( void )
{ {
mono_set_dirs( "mods/deathmatch/mono/lib", "mods/deathmatch/mono/etc" ); 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_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" ); 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(); CMonoFunctions::AddInternals();
this->m_pGC = new CMonoGC; this->m_pGC = new CMonoGC;
@ -223,4 +234,19 @@ CLuaArguments CMonoInterface::MonoArrayToLuaArguments( MonoArray* pArray )
} }
return pLuaArguments; 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 class CMonoInterface
{ {
private: private:
MonoDomain* m_pMonoDomain; MonoDomain* m_pMonoDomain;
CMonoGC* m_pGC; CMonoGC* m_pGC;
static MonoAssembly* m_pMTALib;
public: 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 #pragma region Static methods
static string GetBinariesDirectory( void ) static string GetBinariesDirectory( void )
{ {
return "mods/deathmatch/resources/[ire]"; return "mods/deathmatch/resources/[ire]";
} }
static MonoAssembly* GetMTALib( void );
static CLuaArguments MonoArrayToLuaArguments( MonoArray* pArray ); 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 #pragma endregion
}; };

View File

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

View File

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