From 112d6b869467e4d5756227e4a5bfc8359bd5d884 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 16 Feb 2009 12:22:38 -0500 Subject: Engine: Fixed EventCall bug Previously, if ObjectLoader threw a ResourceNotFoundException in an event thread, the event would not catch it and the event would simply end (and most likely restart if the user was still holding the action key). --- .../gamestate/mapview/event/EventCall.java | 2 +- .../gamestate/mapview/event/EventHandler.java | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java index f577cc2..7214528 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java @@ -11,7 +11,7 @@ import java.util.concurrent.Future; * * @author hatkirby */ -public abstract class EventCall extends SpecialEvent implements Runnable { +public abstract class EventCall extends SpecialEvent { public static EventCall getEmptyEventCall() { diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java index 05997e0..a8a626f 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java @@ -5,6 +5,8 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; +import com.fourisland.fourpuzzle.PuzzleApplication; +import com.fourisland.fourpuzzle.util.ResourceNotFoundException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -32,13 +34,29 @@ public class EventHandler { public static Future runEvent(EventCall callback) { - eventAction = eventExecutorService.submit(callback); + eventAction = eventExecutorService.submit(eventThread(callback)); return eventAction; } public static Future runParallel(EventCall callback) { - return parallelExecutorService.submit(callback); + return parallelExecutorService.submit(eventThread(callback)); + } + + private static Runnable eventThread(final EventCall callback) + { + return new Runnable() { + public void run() + { + try + { + callback.run(); + } catch (ResourceNotFoundException ex) + { + PuzzleApplication.INSTANCE.reportError(ex); + } + } + }; } public static boolean isRunningEvent() -- cgit 1.4.1