Исправлен баг с крашем сервера при повторном запуске ресурса

This commit is contained in:
Kernell 2015-03-13 13:14:45 +03:00
parent b19787ef76
commit 96734fe4c5
3 changed files with 18 additions and 7 deletions

View File

@ -34,17 +34,26 @@ CResource::CResource( lua_State *pLuaVM, string sName )
CResource::~CResource( void ) CResource::~CResource( void )
{ {
if( this->m_pMonoGCHandle ) mono_domain_set( mono_get_root_domain(), false );
{
mono_gchandle_free( this->m_pMonoGCHandle );
}
if( this->m_pMonoDomain ) if( this->m_pMonoDomain )
{ {
mono_domain_unload( this->m_pMonoDomain ); mono_domain_unload( this->m_pMonoDomain );
} }
mono_gc_collect( mono_gc_max_generation() );
g_pResourceManager->RemoveFromList( this ); g_pResourceManager->RemoveFromList( this );
this->m_pMonoAssembly = NULL;
this->m_pMonoAssemblyLib = NULL;
this->m_pMonoGCHandle = NULL;
this->m_pMonoDomain = NULL;
this->m_pMonoImage = NULL;
this->m_pMonoImageLib = NULL;
this->m_pMonoClass = NULL;
this->m_pLuaVM = NULL;
} }
bool CResource::Init( void ) bool CResource::Init( void )
@ -88,7 +97,7 @@ bool CResource::Init( void )
MonoObject *pMonoObject = mono_object_new( this->m_pMonoDomain, this->m_pMonoClass ); MonoObject *pMonoObject = mono_object_new( this->m_pMonoDomain, this->m_pMonoClass );
this->m_pMonoGCHandle = mono_gchandle_new( pMonoObject, true ); mono_gchandle_new( pMonoObject, false );
mono_runtime_object_init( pMonoObject ); mono_runtime_object_init( pMonoObject );

View File

@ -35,7 +35,7 @@ public:
// mono_config_parse( NULL ); // mono_config_parse( NULL );
mono_debug_init( MONO_DEBUG_FORMAT_MONO ); // mono_debug_init( MONO_DEBUG_FORMAT_MONO );
this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" ); this->m_pMonoDomain = mono_jit_init_version( "Mono Root", "v4.0.30319" );

View File

@ -46,6 +46,8 @@ extern "C"
#include <mono/metadata/mono-debug.h> #include <mono/metadata/mono-debug.h>
#include <mono/metadata/debug-helpers.h> #include <mono/metadata/debug-helpers.h>
#include <mono/metadata/environment.h> #include <mono/metadata/environment.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/mono-gc.h>
#include "include/ILuaModuleManager.h" #include "include/ILuaModuleManager.h"