mirror of
https://github.com/ChronosX88/mta-mono.git
synced 2024-11-22 10:12:20 +00:00
Выгрузка домена ресурса крашит сервер при следующем запуске (ticket #2)
This commit is contained in:
parent
a79c28940a
commit
424fc2dfd3
@ -27,44 +27,45 @@ CResource::CResource( CMonoInterface* pMono, lua_State *pLuaVM, string sName )
|
|||||||
this->m_sName = sName;
|
this->m_sName = sName;
|
||||||
|
|
||||||
this->m_pMonoAssembly = nullptr;
|
this->m_pMonoAssembly = nullptr;
|
||||||
this->m_pMonoGCHandle = 0;
|
|
||||||
this->m_pMonoDomain = nullptr;
|
this->m_pMonoDomain = nullptr;
|
||||||
this->m_pMonoImage = nullptr;
|
this->m_pMonoImage = nullptr;
|
||||||
this->m_pMonoClass = nullptr;
|
this->m_pMonoClass = nullptr;
|
||||||
|
|
||||||
|
this->m_uiGCHandle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CResource::~CResource( void )
|
CResource::~CResource( void )
|
||||||
{
|
{
|
||||||
|
if( this->m_uiGCHandle )
|
||||||
|
{
|
||||||
|
mono_gchandle_free( this->m_uiGCHandle );
|
||||||
|
|
||||||
|
this->m_uiGCHandle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
this->GetMono()->GetGC()->Collect( this->GetMono()->GetGC()->GetMaxGeneration() );
|
this->GetMono()->GetGC()->Collect( this->GetMono()->GetGC()->GetMaxGeneration() );
|
||||||
|
|
||||||
mono_domain_set( mono_get_root_domain(), false );
|
mono_domain_set( mono_get_root_domain(), true );
|
||||||
|
|
||||||
if( this->m_pMonoDomain )
|
|
||||||
{
|
|
||||||
this->m_pMonoDomain->Unload();
|
|
||||||
this->m_pMonoDomain = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_pResourceManager->RemoveFromList( this );
|
g_pResourceManager->RemoveFromList( this );
|
||||||
|
|
||||||
this->m_pMonoAssembly = nullptr;
|
this->m_pMonoAssembly = nullptr;
|
||||||
this->m_pMonoGCHandle = 0;
|
|
||||||
this->m_pMonoDomain = nullptr;
|
this->m_pMonoDomain = nullptr;
|
||||||
this->m_pMonoImage = nullptr;
|
this->m_pMonoImage = nullptr;
|
||||||
this->m_pMonoClass = nullptr;
|
this->m_pMonoClass = nullptr;
|
||||||
|
|
||||||
this->m_pMono = nullptr;
|
this->m_pMono = nullptr;
|
||||||
this->m_pLuaVM = nullptr;
|
this->m_pLuaVM = nullptr;
|
||||||
this->m_sName = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CResource::CallEvent( string strEventName, void* pThis, void* pSource, void* pClient, void **args )
|
bool CResource::CallEvent( string strEventName, void* pThis, void* pSource, void* pClient, void **args )
|
||||||
{
|
{
|
||||||
MonoEvent* pEvent = nullptr;
|
MonoEvent* pEvent = nullptr;
|
||||||
MonoMethod* method = nullptr;
|
MonoMethod* method = nullptr;
|
||||||
MonoClass* klass = this->GetDomain()->GetMTALib()->GetClass( "Element" )->GetMonoPtr();
|
CMonoClass* pClass = this->GetDomain()->GetMTALib()->GetClass( "Element" );
|
||||||
|
MonoClass* klass = pClass->GetMonoPtr();
|
||||||
|
|
||||||
g_pModuleManager->DebugPrintf( this->GetLua(), "CResource::CallEvent::%s", strEventName.substr( 2 ).c_str() );
|
g_pModuleManager->DebugPrintf( this->GetLua(), "[%s] CResource::CallEvent::%s", this->m_sName.c_str(), strEventName.substr( 2 ).c_str() );
|
||||||
|
|
||||||
gpointer iter;
|
gpointer iter;
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ void CResource::RegisterEvents( void )
|
|||||||
{
|
{
|
||||||
if( g_pModuleManager->RegisterFunction( this->m_pLuaVM, "mono_event_handler", CFunctions::monoEventHandler ) )
|
if( g_pModuleManager->RegisterFunction( this->m_pLuaVM, "mono_event_handler", CFunctions::monoEventHandler ) )
|
||||||
{
|
{
|
||||||
luaL_dostring( this->m_pLuaVM, "addEventHandler( 'onElementDestroy', root, \
|
luaL_dostring( this->m_pLuaVM, "addEventHandler( 'onElementDestroy', resourceRoot, \
|
||||||
function( ... ) \
|
function( ... ) \
|
||||||
mono_event_handler( eventName, this, source, client, ... );\
|
mono_event_handler( eventName, this, source, client, ... );\
|
||||||
end \
|
end \
|
||||||
@ -153,10 +154,10 @@ bool CResource::Init( void )
|
|||||||
|
|
||||||
MonoObject *pMonoObject = this->m_pMonoDomain->CreateObject( this->m_pMonoClass );
|
MonoObject *pMonoObject = this->m_pMonoDomain->CreateObject( this->m_pMonoClass );
|
||||||
|
|
||||||
mono_gchandle_new( pMonoObject, false );
|
|
||||||
|
|
||||||
mono_runtime_object_init( pMonoObject );
|
mono_runtime_object_init( pMonoObject );
|
||||||
|
|
||||||
|
this->m_uiGCHandle = mono_gchandle_new( pMonoObject, true );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,8 @@ private:
|
|||||||
MonoAssembly* m_pMonoAssembly;
|
MonoAssembly* m_pMonoAssembly;
|
||||||
MonoImage* m_pMonoImage;
|
MonoImage* m_pMonoImage;
|
||||||
MonoClass* m_pMonoClass;
|
MonoClass* m_pMonoClass;
|
||||||
uint32_t m_pMonoGCHandle;
|
|
||||||
|
uint32_t m_uiGCHandle;
|
||||||
|
|
||||||
lua_State* m_pLuaVM;
|
lua_State* m_pLuaVM;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user