From a3e1c6e09e2c7ce9b68118de6387c77aad9530db Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 9 Dec 2008 23:23:15 +0000 Subject: [PATCH] Fixup. If there's an error when calling the callback function, we were assuming it was an argument-related error and trying again. However, this is sorta bad behavior as we don't want to call twice into a callback. In the case I was seeing, the first time in caused an NPE, but popped up a panel, and the second try was no-opping because the panel was already up (but misconfigured). So: don't even try a second call, because it looks like flash will accept args to an argless function. We'll have to try this out for a while and see if it works. If so, I can neaten this code. If not, I'll uncomment some of this and try a more surgical approach (only catch ArgumentError, only retry if we had 1 boolean arg.) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5585 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/CommandEvent.as | 47 +++++++++++++--------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/as/com/threerings/util/CommandEvent.as b/src/as/com/threerings/util/CommandEvent.as index 43c1d0cbb..7174f88f6 100644 --- a/src/as/com/threerings/util/CommandEvent.as +++ b/src/as/com/threerings/util/CommandEvent.as @@ -35,7 +35,7 @@ public class CommandEvent extends Event * Use this method to dispatch CommandEvents. */ public static function dispatch ( - disp :IEventDispatcher, cmdOrFn :Object, arg :Object = null) :void + disp :IEventDispatcher, cmdOrFn :Object, arg :Object = null) :void { if (cmdOrFn is Function) { var fn :Function = (cmdOrFn as Function); @@ -53,23 +53,31 @@ public class CommandEvent extends Event } else { args = [ arg ]; } + + // now trying calling it + var err :Error = null; try { fn.apply(null, args); - } catch (err :Error) { - if (arg == null) { - try { - // try with no args - fn(); - err = null; // on success, clear the error - } catch (err2 :Error) { - err = err2; - } - } - if (err != null) { - var log :Log = Log.getLog(CommandEvent); - log.warning("Unable to call command callback, stack trace follows."); - log.logStackTrace(err); - } + +// Commented out 2008-12-09 by Ray. I'm not sure we need this, it seems you can pass args +// to an argless function without error. +// } catch (ae :ArgumentError) { +// if (arg is Boolean) { +// // try with no args +// try { +// fn(); +// } catch (e2 :Error) { +// err = e2; +// } +// } else { +// err = ae; +// } + + } catch (e :Error) { + err = e; + } + if (err != null) { + Log.getLog(CommandEvent).warning("Unable to call callback.", err); } } else if (cmdOrFn is String) { @@ -80,8 +88,8 @@ public class CommandEvent extends Event // Dispatch it. A return value of true means that the event was // never cancelled, so we complain. if (disp == null || disp.dispatchEvent(event)) { - Log.getLog(CommandEvent).warning("Unhandled controller command " + - "[cmd=" + cmd + ", arg=" + arg + ", disp=" + disp + "]."); + Log.getLog(CommandEvent).warning("Unhandled controller command", + "cmd", cmd, "arg", arg, "disp", disp); } } else { @@ -92,7 +100,8 @@ public class CommandEvent extends Event /** * Configure a bridge from something like a pop-up window to an alternate target. */ - public static function configureBridge (source :IEventDispatcher, target :IEventDispatcher) :void + public static function configureBridge ( + source :IEventDispatcher, target :IEventDispatcher) :void { source.addEventListener(COMMAND, function (event :CommandEvent) :void {