diff --git a/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java b/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java index 49b1294b7..6dd879b3a 100644 --- a/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java +++ b/engine/src/android/com/jme3/system/android/JmeAndroidSystem.java @@ -1,6 +1,7 @@ package com.jme3.system.android; import android.app.Activity; +import android.app.AlertDialog; import android.os.Environment; import com.jme3.asset.AndroidAssetManager; import com.jme3.asset.AssetManager; @@ -41,6 +42,22 @@ public class JmeAndroidSystem extends JmeSystemDelegate { return new AndroidAssetManager(null); } + @Override + public void showErrorDialog(String message) { + final String finalMsg = message; + final String finalTitle = "Error in jMonkeyEngine app"; + final Activity context = JmeAndroidSystem.getActivity(); + + context.runOnUiThread(new Runnable() { + @Override + public void run() { + AlertDialog dialog = new AlertDialog.Builder(context) + .setTitle(finalTitle).setMessage(finalMsg).create(); + dialog.show(); + } + }); + } + @Override public boolean showSettingsDialog(AppSettings sourceSettings, boolean loadFromRegistry) { return true; diff --git a/engine/src/core/com/jme3/app/Application.java b/engine/src/core/com/jme3/app/Application.java index adf9c33db..688c2ef65 100644 --- a/engine/src/core/com/jme3/app/Application.java +++ b/engine/src/core/com/jme3/app/Application.java @@ -43,8 +43,8 @@ import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; import com.jme3.renderer.Renderer; import com.jme3.renderer.ViewPort; -import com.jme3.system.*; import com.jme3.system.JmeContext.Type; +import com.jme3.system.*; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.Callable; @@ -518,8 +518,16 @@ public class Application implements SystemListener { * Internal use only. */ public void handleError(String errMsg, Throwable t){ + // Print error to log. logger.log(Level.SEVERE, errMsg, t); - // user should add additional code to handle the error. + // Display error message on screen + if (t != null) { + JmeSystem.showErrorDialog(errMsg + "\n" + t.getClass().getSimpleName() + + (t.getMessage() != null ? ": " + t.getMessage() : "")); + } else { + JmeSystem.showErrorDialog(errMsg); + } + stop(); // stop the application } diff --git a/engine/src/core/com/jme3/system/JmeSystem.java b/engine/src/core/com/jme3/system/JmeSystem.java index 1639562b5..f6260c4ec 100644 --- a/engine/src/core/com/jme3/system/JmeSystem.java +++ b/engine/src/core/com/jme3/system/JmeSystem.java @@ -123,6 +123,19 @@ public class JmeSystem { return systemDelegate.newAudioRenderer(settings); } + /** + * Displays an error message to the user in whichever way the context + * feels is appropriate. If this is a headless or an offscreen surface + * context, this method should do nothing. + * + * @param message The error message to display. May contain new line + * characters. + */ + public static void showErrorDialog(String message){ + checkDelegate(); + systemDelegate.showErrorDialog(message); + } + public static void initialize(AppSettings settings) { checkDelegate(); systemDelegate.initialize(settings); diff --git a/engine/src/core/com/jme3/system/JmeSystemDelegate.java b/engine/src/core/com/jme3/system/JmeSystemDelegate.java index e0f6fa5ec..aef6cede5 100644 --- a/engine/src/core/com/jme3/system/JmeSystemDelegate.java +++ b/engine/src/core/com/jme3/system/JmeSystemDelegate.java @@ -100,6 +100,8 @@ public abstract class JmeSystemDelegate { public abstract AssetManager newAssetManager(); + public abstract void showErrorDialog(String message); + public abstract boolean showSettingsDialog(AppSettings sourceSettings, boolean loadFromRegistry); private boolean is64Bit(String arch) { diff --git a/engine/src/desktop/com/jme3/system/JmeDesktopSystem.java b/engine/src/desktop/com/jme3/system/JmeDesktopSystem.java index 9a8eac43f..66c29f498 100644 --- a/engine/src/desktop/com/jme3/system/JmeDesktopSystem.java +++ b/engine/src/desktop/com/jme3/system/JmeDesktopSystem.java @@ -38,11 +38,13 @@ import com.jme3.asset.AssetNotFoundException; import com.jme3.asset.DesktopAssetManager; import com.jme3.audio.AudioRenderer; import com.jme3.system.JmeContext.Type; +import java.awt.EventQueue; import java.io.IOException; import java.net.URL; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; +import javax.swing.JOptionPane; import javax.swing.SwingUtilities; /** @@ -61,6 +63,17 @@ public class JmeDesktopSystem extends JmeSystemDelegate { return new DesktopAssetManager(null); } + @Override + public void showErrorDialog(String message) { + final String msg = message; + final String title = "Error in jMonkeyEngine app"; + EventQueue.invokeLater(new Runnable() { + public void run() { + JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE); + } + }); + } + @Override public boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) { if (SwingUtilities.isEventDispatchThread()) {