Skip to content

Commit

Permalink
Better handling of exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexp-sssup committed May 19, 2010
1 parent 7c9ad9e commit dd1bcb4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
7 changes: 6 additions & 1 deletion abc.cpp
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion abc_opcodes.cpp
Expand Up @@ -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<Class_base*>(tmp);
ret->max_level=ret->super->max_level+1;
ret->setLevel(ret->max_level);
Expand Down
2 changes: 0 additions & 2 deletions asobjects.cpp
Expand Up @@ -17,8 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#define __STDC_LIMIT_MACROS
#define __STDC_CONSTANT_MACROS
#include <list>
#include <algorithm>
//#include <libxml/parser.h>
Expand Down
2 changes: 1 addition & 1 deletion exceptions.h
Expand Up @@ -25,7 +25,7 @@

#define assert_and_throw(cond) if(!(cond)) \
{ \
throw AssertionException(##cond); \
throw AssertionException(#cond); \
}


Expand Down
7 changes: 6 additions & 1 deletion flashutils.cpp
Expand Up @@ -229,7 +229,12 @@ void Timer::execute()
sys->currentVm->addEvent(this,Class<TimerEvent>::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();
}
Expand Down
13 changes: 9 additions & 4 deletions frame.cpp
Expand Up @@ -93,10 +93,15 @@ void Frame::init(MovieClip* parent, list <pair<PlaceInfo, IDisplayListElem*> >&
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
}
}
Expand Down
31 changes: 20 additions & 11 deletions swf.cpp
Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -1426,10 +1430,15 @@ void RootMovieClip::initialize()
//Now signal the completion for this root
sys->currentVm->addEvent(loaderInfo,Class<Event>::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();
}
}

Expand Down

0 comments on commit dd1bcb4

Please sign in to comment.