crash fix on exit

This commit is contained in:
David Rose 2009-12-21 23:31:47 +00:00
parent 56bbb780ee
commit 029eb75f78
3 changed files with 36 additions and 14 deletions

View File

@ -428,7 +428,7 @@ int PPInstance::LoadPlugin( const std::string& dllFilename )
{
if ( !m_pluginLoaded )
{
s_instanceCount += 1;
ref_plugin();
m_pluginLoaded = true;
}
@ -479,22 +479,37 @@ int PPInstance::UnloadPlugin()
if ( m_pluginLoaded )
{
m_pluginLoaded = false;
assert( s_instanceCount > 0 );
s_instanceCount -= 1;
if ( s_instanceCount == 0 && is_plugin_loaded() )
{
unload_plugin();
m_isInit = false;
// This pointer is no longer valid and must be reset for next
// time.
PPBrowserObject::clear_class_definition();
}
m_isInit = false;
unref_plugin();
}
return error;
}
// Increments the reference count on the "plugin" library (i.e. the
// core API). Call unref_plugin() later to decrement this count.
void PPInstance::
ref_plugin() {
s_instanceCount += 1;
}
// Decrements the reference count on the "plugin" library. This must
// correspond to an earlier call to ref_plugin(). When the last
// reference is removed, the plugin will be unloaded.
void PPInstance::
unref_plugin() {
assert( s_instanceCount > 0 );
s_instanceCount -= 1;
if ( s_instanceCount == 0 && is_plugin_loaded() ) {
nout << "Unloading core API\n";
unload_plugin();
// This pointer is no longer valid and must be reset for next
// time.
PPBrowserObject::clear_class_definition();
}
}
int PPInstance::Start( const std::string& p3dFilename )
{
m_eventStop.ResetEvent();

View File

@ -50,6 +50,9 @@ public:
int LoadPlugin( const std::string& dllFilename );
int UnloadPlugin( void );
static void ref_plugin();
static void unref_plugin();
int Start( const std::string& p3dFileName );
std::string GetHostUrl( );

View File

@ -14,6 +14,7 @@
#include "stdafx.h"
#include "PPPandaObject.h"
#include "PPInstance.h"
#include "load_plugin.h"
PPandaObject::PPandaObject( PPInterface* interfac, P3D_object* p3dObject ) :
@ -24,6 +25,7 @@ PPandaObject::PPandaObject( PPInterface* interfac, P3D_object* p3dObject ) :
P3D_OBJECT_INCREF( m_p3dObject );
}
AddRef();
PPInstance::ref_plugin();
}
PPandaObject::~PPandaObject()
@ -35,10 +37,12 @@ PPandaObject::~PPandaObject()
// Clean up the p3d_object, but only if we haven't already
// unloaded the plugin.
if ( m_p3dObject && is_plugin_loaded() )
if ( m_p3dObject )
{
P3D_OBJECT_DECREF( m_p3dObject );
}
PPInstance::unref_plugin();
}
// Dispatch Methods