From 424fc2dfd3ee28bf3ce96780e43337dead48060e Mon Sep 17 00:00:00 2001 From: Kernell Date: Mon, 30 Nov 2015 06:34:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B5?= =?UTF-8?q?=D1=81=D1=83=D1=80=D1=81=D0=B0=20=D0=BA=D1=80=D0=B0=D1=88=D0=B8?= =?UTF-8?q?=D1=82=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D1=8E=D1=89=D0=B5=D0=BC?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B5=20(ticket=20#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mta-mono/src/CResource.cpp | 31 ++++++++++++++++--------------- mta-mono/src/CResource.h | 3 ++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mta-mono/src/CResource.cpp b/mta-mono/src/CResource.cpp index 975d20b..a7cdde6 100644 --- a/mta-mono/src/CResource.cpp +++ b/mta-mono/src/CResource.cpp @@ -27,44 +27,45 @@ CResource::CResource( CMonoInterface* pMono, lua_State *pLuaVM, string sName ) this->m_sName = sName; this->m_pMonoAssembly = nullptr; - this->m_pMonoGCHandle = 0; this->m_pMonoDomain = nullptr; this->m_pMonoImage = nullptr; this->m_pMonoClass = nullptr; + + this->m_uiGCHandle = 0; } 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() ); - mono_domain_set( mono_get_root_domain(), false ); - - if( this->m_pMonoDomain ) - { - this->m_pMonoDomain->Unload(); - this->m_pMonoDomain = nullptr; - } + mono_domain_set( mono_get_root_domain(), true ); g_pResourceManager->RemoveFromList( this ); this->m_pMonoAssembly = nullptr; - this->m_pMonoGCHandle = 0; this->m_pMonoDomain = nullptr; this->m_pMonoImage = nullptr; this->m_pMonoClass = nullptr; this->m_pMono = nullptr; this->m_pLuaVM = nullptr; - this->m_sName = nullptr; } bool CResource::CallEvent( string strEventName, void* pThis, void* pSource, void* pClient, void **args ) { MonoEvent* pEvent = 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; @@ -105,7 +106,7 @@ void CResource::RegisterEvents( void ) { 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( ... ) \ mono_event_handler( eventName, this, source, client, ... );\ end \ @@ -153,10 +154,10 @@ bool CResource::Init( void ) MonoObject *pMonoObject = this->m_pMonoDomain->CreateObject( this->m_pMonoClass ); - mono_gchandle_new( pMonoObject, false ); - mono_runtime_object_init( pMonoObject ); + this->m_uiGCHandle = mono_gchandle_new( pMonoObject, true ); + return true; } diff --git a/mta-mono/src/CResource.h b/mta-mono/src/CResource.h index 0c48fb5..8ca2251 100644 --- a/mta-mono/src/CResource.h +++ b/mta-mono/src/CResource.h @@ -28,7 +28,8 @@ private: MonoAssembly* m_pMonoAssembly; MonoImage* m_pMonoImage; MonoClass* m_pMonoClass; - uint32_t m_pMonoGCHandle; + + uint32_t m_uiGCHandle; lua_State* m_pLuaVM;