fix a memory bug

This commit is contained in:
David Rose 2009-06-24 03:51:36 +00:00
parent 8a48e4593e
commit 8bab079cc7
5 changed files with 34 additions and 23 deletions

View File

@ -153,7 +153,9 @@ set_property(const string &property_name, const string &value) {
////////////////////////////////////////////////////////////////////
bool P3DInstance::
has_request() {
nout << "has_request called, getting lock\n" << flush;
ACQUIRE_LOCK(_request_lock);
nout << "got lock\n" << flush;
bool any_requests = !_pending_requests.empty();
RELEASE_LOCK(_request_lock);
return any_requests;
@ -202,10 +204,11 @@ add_request(P3D_request *request) {
RELEASE_LOCK(_request_lock);
// Asynchronous notification for anyone who cares.
nout << "request_ready, calling " << _func << "\n" << flush;
nout << "request_ready, calling " << (void *)_func << "\n" << flush;
if (_func != NULL) {
_func(this);
}
nout << "done calling " << (void *)_func << "\n" << flush;
// Synchronous notification for pollers.
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();

View File

@ -23,6 +23,7 @@
#else
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#endif
P3DInstanceManager *P3DInstanceManager::_global_ptr;
@ -170,12 +171,16 @@ finish_instance(P3DInstance *inst) {
////////////////////////////////////////////////////////////////////
P3DInstance *P3DInstanceManager::
check_request() {
nout << "check_request\n" << flush;
Instances::iterator ii;
for (ii = _instances.begin(); ii != _instances.end(); ++ii) {
P3DInstance *inst = (*ii);
cerr << " checking request for " << inst << "\n" << flush;
if (inst->has_request()) {
cerr << " true\n" << flush;
return inst;
}
cerr << " false\n" << flush;
}
return NULL;

View File

@ -20,6 +20,10 @@
string for the default. */
#$[]define P3D_PLUGIN_P3DPYTHON "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3DPYTHON]]]"
/* Temporary: the location at which p3d_plugin.dll can be found. Empty
string for the default. */
#$[]define P3D_PLUGIN_P3D_PLUGIN "$[osfilename $[P3D_PLUGIN_P3D_PLUGIN]]"
/* The string that corresponds to this particular platform. */
#if $[not $[P3D_PLUGIN_PLATFORM]]
#if $[WINDOWS_PLATFORM]

View File

@ -212,13 +212,6 @@ destroy_stream(NPStream *stream, NPReason reason) {
}
break;
case PPDownloadRequest::RT_core_dll:
// This is the one case we don't start with GetUrlNotify, so we'll
// never get a url_notify call on this one. So, we have to delete
// the PPDownloadRequest object here.
delete req;
break;
default:
break;
}
@ -255,17 +248,12 @@ url_notify(const char *url, NPReason reason, void *notifyData) {
req->_notified_done = true;
}
break;
case PPDownloadRequest::RT_core_dll:
// Shouldn't be possible to get here.
assert(false);
break;
default:
break;
}
delete req;
// delete req;
}
////////////////////////////////////////////////////////////////////
@ -306,14 +294,21 @@ stream_as_file(NPStream *stream, const char *fname) {
PPDownloadRequest *req = (PPDownloadRequest *)(stream->notifyData);
switch (req->_rtype) {
case PPDownloadRequest::RT_core_dll:
// This is the core API DLL (or dylib or whatever). Now that
// we've downloaded it, we can load it.
logfile << "got plugin\n";
if (!load_plugin(filename)) {
logfile << "Unable to launch core API.\n";
break;
{
// This is the core API DLL (or dylib or whatever). Now that
// we've downloaded it, we can load it.
logfile << "got plugin " << filename << "\n" << flush;
string override_filename = P3D_PLUGIN_P3D_PLUGIN;
if (!override_filename.empty()) {
filename = override_filename;
}
if (!load_plugin(filename)) {
logfile << "Unable to launch core API.\n";
break;
}
logfile << "loaded core API " << filename << "\n" << flush;
create_instance();
}
create_instance();
break;
case PPDownloadRequest::RT_instance_data:

View File

@ -47,6 +47,7 @@ static void
handle_request_loop() {
assert(is_plugin_loaded());
logfile << "about to call P3D_check_request()\n" << flush;
P3D_instance *p3d_inst = P3D_check_request(false);
logfile << "P3D_check_request() returns " << p3d_inst << "\n" << flush;
while (p3d_inst != (P3D_instance *)NULL) {
@ -100,14 +101,17 @@ request_ready(P3D_instance *instance) {
// Since we might be in a sub-thread at this point, use a timer to
// forward this event to the main thread.
ACQUIRE_LOCK(_timer_lock);
#ifdef _WIN32
ACQUIRE_LOCK(_timer_lock);
if (_timer == 0) {
_timer = SetTimer(NULL, 0, 0, win_timer_func);
logfile << "_timer = " << _timer << "\n" << flush;
}
#endif
RELEASE_LOCK(_timer_lock);
#else
// TODO: send the message to the main thread properly.
handle_request_loop();
#endif
}