From dd1bcb46bb449b6aca434689005031cb58e98aab Mon Sep 17 00:00:00 2001 From: Alessandro Date: Wed, 19 May 2010 05:14:59 +0200 Subject: [PATCH] Better handling of exceptions --- abc.cpp | 7 ++++++- abc_opcodes.cpp | 2 +- asobjects.cpp | 2 -- exceptions.h | 2 +- flashutils.cpp | 7 ++++++- frame.cpp | 13 +++++++++---- swf.cpp | 31 ++++++++++++++++++++----------- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/abc.cpp b/abc.cpp index b547b7da73..1fcce45378 100644 --- a/abc.cpp +++ b/abc.cpp @@ -72,7 +72,12 @@ void DoABCTag::execute(RootMovieClip*) LOG(LOG_CALLS,"ABC Exec " << Name); sys->currentVm->addEvent(NULL,new ABCContextInitEvent(context)); SynchronizationEvent* se=new SynchronizationEvent; - sys->currentVm->addEvent(NULL,se); + bool added=sys->currentVm->addEvent(NULL,se); + if(!added) + { + se->decRef(); + throw RunTimeException("Could not add event"); + } se->wait(); se->decRef(); } diff --git a/abc_opcodes.cpp b/abc_opcodes.cpp index 0b8a964a75..ee9cb7d05b 100644 --- a/abc_opcodes.cpp +++ b/abc_opcodes.cpp @@ -2094,7 +2094,7 @@ void ABCVm::newClass(call_context* th, int n) //Null is a "valid" base class if(tmp->getObjectType()!=T_NULL) { - assert(tmp->getObjectType()==T_CLASS); + assert_and_throw(tmp->getObjectType()==T_CLASS); ret->super=static_cast(tmp); ret->max_level=ret->super->max_level+1; ret->setLevel(ret->max_level); diff --git a/asobjects.cpp b/asobjects.cpp index dbd7905d05..a726dae3c9 100644 --- a/asobjects.cpp +++ b/asobjects.cpp @@ -17,8 +17,6 @@ along with this program. If not, see . **************************************************************************/ -#define __STDC_LIMIT_MACROS -#define __STDC_CONSTANT_MACROS #include #include //#include diff --git a/exceptions.h b/exceptions.h index 7feb8a693f..20938f0c46 100644 --- a/exceptions.h +++ b/exceptions.h @@ -25,7 +25,7 @@ #define assert_and_throw(cond) if(!(cond)) \ { \ - throw AssertionException(##cond); \ + throw AssertionException(#cond); \ } diff --git a/flashutils.cpp b/flashutils.cpp index a0207c40e2..8f019aa16e 100644 --- a/flashutils.cpp +++ b/flashutils.cpp @@ -229,7 +229,12 @@ void Timer::execute() sys->currentVm->addEvent(this,Class::getInstanceS("timer")); //Do not spam timer events until this is done SynchronizationEvent* se=new SynchronizationEvent; - sys->currentVm->addEvent(NULL,se); + bool added=sys->currentVm->addEvent(NULL,se); + if(!added) + { + se->decRef(); + throw RunTimeException("Could not add event"); + } se->wait(); se->decRef(); } diff --git a/frame.cpp b/frame.cpp index db4ef2d2ca..d7ea225d44 100644 --- a/frame.cpp +++ b/frame.cpp @@ -93,10 +93,15 @@ void Frame::init(MovieClip* parent, list >& if(sys->currentVm) { //We stop execution until execution engine catches up - SynchronizationEvent* s=new SynchronizationEvent; - sys->currentVm->addEvent(NULL, s); - s->wait(); - s->decRef(); + SynchronizationEvent* se=new SynchronizationEvent; + bool added=sys->currentVm->addEvent(NULL, se); + if(!added) + { + se->decRef(); + throw RunTimeException("Could not add event"); + } + se->wait(); + se->decRef(); //Now the bindings are effective for all tags } } diff --git a/swf.cpp b/swf.cpp index 8c887840b1..be0de2e0b8 100644 --- a/swf.cpp +++ b/swf.cpp @@ -203,14 +203,18 @@ bool SystemState::shouldTerminate() const void SystemState::setError(string& c) { - error=true; - errorCause=c; - timerThread->stop(); - if(renderThread) + //We record only the first error for easier fix and reporting + if(!error) { - //Disable timed rendering - removeJob(renderThread); - renderThread->draw(); + error=true; + errorCause=c; + timerThread->stop(); + if(renderThread) + { + //Disable timed rendering + removeJob(renderThread); + renderThread->draw(); + } } } @@ -1426,10 +1430,15 @@ void RootMovieClip::initialize() //Now signal the completion for this root sys->currentVm->addEvent(loaderInfo,Class::getInstanceS("init")); //Wait for handling of all previous events - SynchronizationEvent* sync=new SynchronizationEvent; - sys->currentVm->addEvent(NULL, sync); - sync->wait(); - sync->decRef(); + SynchronizationEvent* se=new SynchronizationEvent; + bool added=sys->currentVm->addEvent(NULL, se); + if(!added) + { + se->decRef(); + throw RunTimeException("Could not add event"); + } + se->wait(); + se->decRef(); } }