use of java.lang.Thread.UncaughtExceptionHandler in project MinecraftForge by MinecraftForge.
the class SplashProgress method start.
public static void start() {
File configFile = new File(Minecraft.getMinecraft().mcDataDir, "config/splash.properties");
File parent = configFile.getParentFile();
if (!parent.exists())
parent.mkdirs();
FileReader r = null;
config = new Properties();
try {
r = new FileReader(configFile);
config.load(r);
} catch (IOException e) {
FMLLog.info("Could not load splash.properties, will create a default one");
} finally {
IOUtils.closeQuietly(r);
}
//Some system do not support this and have weird effects so we need to detect and disable by default.
//The user can always force enable it if they want to take the responsibility for bugs.
//For now macs derp so disable them.
boolean defaultEnabled = !System.getProperty("os.name").toLowerCase().contains("mac");
// Enable if we have the flag, and there's either no optifine, or optifine has added a key to the blackboard ("optifine.ForgeSplashCompatible")
// Optifine authors - add this key to the blackboard if you feel your modifications are now compatible with this code.
enabled = getBool("enabled", defaultEnabled) && ((!FMLClientHandler.instance().hasOptifine()) || Launch.blackboard.containsKey("optifine.ForgeSplashCompatible"));
rotate = getBool("rotate", false);
showMemory = getBool("showMemory", true);
logoOffset = getInt("logoOffset", 0);
backgroundColor = getHex("background", 0xFFFFFF);
fontColor = getHex("font", 0x000000);
barBorderColor = getHex("barBorder", 0xC0C0C0);
barColor = getHex("bar", 0xCB3D35);
barBackgroundColor = getHex("barBackground", 0xFFFFFF);
memoryGoodColor = getHex("memoryGood", 0x78CB34);
memoryWarnColor = getHex("memoryWarn", 0xE6E84A);
memoryLowColor = getHex("memoryLow", 0xE42F2F);
final ResourceLocation fontLoc = new ResourceLocation(getString("fontTexture", "textures/font/ascii.png"));
final ResourceLocation logoLoc = new ResourceLocation(getString("logoTexture", "textures/gui/title/mojang.png"));
final ResourceLocation forgeLoc = new ResourceLocation(getString("forgeTexture", "fml:textures/gui/forge.png"));
final ResourceLocation forgeFallbackLoc = new ResourceLocation("fml:textures/gui/forge.png");
File miscPackFile = new File(Minecraft.getMinecraft().mcDataDir, getString("resourcePackPath", "resources"));
FileWriter w = null;
try {
w = new FileWriter(configFile);
config.store(w, "Splash screen properties");
} catch (IOException e) {
FMLLog.log(Level.ERROR, e, "Could not save the splash.properties file");
} finally {
IOUtils.closeQuietly(w);
}
miscPack = createResourcePack(miscPackFile);
if (!enabled)
return;
// getting debug info out of the way, while we still can
FMLCommonHandler.instance().registerCrashCallable(new ICrashCallable() {
public String call() throws Exception {
return "' Vendor: '" + glGetString(GL_VENDOR) + "' Version: '" + glGetString(GL_VERSION) + "' Renderer: '" + glGetString(GL_RENDERER) + "'";
}
public String getLabel() {
return "GL info";
}
});
CrashReport report = CrashReport.makeCrashReport(new Throwable() {
@Override
public String getMessage() {
return "This is just a prompt for computer specs to be printed. THIS IS NOT A ERROR";
}
@Override
public void printStackTrace(final PrintWriter s) {
s.println(getMessage());
}
@Override
public void printStackTrace(final PrintStream s) {
s.println(getMessage());
}
}, "Loading screen debug info");
System.out.println(report.getCompleteReport());
try {
d = new SharedDrawable(Display.getDrawable());
Display.getDrawable().releaseContext();
d.makeCurrent();
} catch (LWJGLException e) {
e.printStackTrace();
disableSplash(e);
}
//Call this ASAP if splash is enabled so that threading doesn't cause issues later
getMaxTextureSize();
//Thread mainThread = Thread.currentThread();
thread = new Thread(new Runnable() {
private final int barWidth = 400;
private final int barHeight = 20;
private final int textHeight2 = 20;
private final int barOffset = 55;
public void run() {
setGL();
fontTexture = new Texture(fontLoc, null);
logoTexture = new Texture(logoLoc, null, false);
forgeTexture = new Texture(forgeLoc, forgeFallbackLoc);
glEnable(GL_TEXTURE_2D);
fontRenderer = new SplashFontRenderer();
glDisable(GL_TEXTURE_2D);
while (!done) {
ProgressBar first = null, penult = null, last = null;
Iterator<ProgressBar> i = ProgressManager.barIterator();
while (i.hasNext()) {
if (first == null)
first = i.next();
else {
penult = last;
last = i.next();
}
}
glClear(GL_COLOR_BUFFER_BIT);
// matrix setup
int w = Display.getWidth();
int h = Display.getHeight();
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(320 - w / 2, 320 + w / 2, 240 + h / 2, 240 - h / 2, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// mojang logo
setColor(backgroundColor);
glEnable(GL_TEXTURE_2D);
logoTexture.bind();
glBegin(GL_QUADS);
logoTexture.texCoord(0, 0, 0);
glVertex2f(320 - 256, 240 - 256);
logoTexture.texCoord(0, 0, 1);
glVertex2f(320 - 256, 240 + 256);
logoTexture.texCoord(0, 1, 1);
glVertex2f(320 + 256, 240 + 256);
logoTexture.texCoord(0, 1, 0);
glVertex2f(320 + 256, 240 - 256);
glEnd();
glDisable(GL_TEXTURE_2D);
// memory usage
if (showMemory) {
glPushMatrix();
glTranslatef(320 - (float) barWidth / 2, 20, 0);
drawMemoryBar();
glPopMatrix();
}
// bars
if (first != null) {
glPushMatrix();
glTranslatef(320 - (float) barWidth / 2, 310, 0);
drawBar(first);
if (penult != null) {
glTranslatef(0, barOffset, 0);
drawBar(penult);
}
if (last != null) {
glTranslatef(0, barOffset, 0);
drawBar(last);
}
glPopMatrix();
}
angle += 1;
// forge logo
setColor(backgroundColor);
float fw = (float) forgeTexture.getWidth() / 2;
float fh = (float) forgeTexture.getHeight() / 2;
if (rotate) {
float sh = Math.max(fw, fh);
glTranslatef(320 + w / 2 - sh - logoOffset, 240 + h / 2 - sh - logoOffset, 0);
glRotatef(angle, 0, 0, 1);
} else {
glTranslatef(320 + w / 2 - fw - logoOffset, 240 + h / 2 - fh - logoOffset, 0);
}
int f = (angle / 5) % forgeTexture.getFrames();
glEnable(GL_TEXTURE_2D);
forgeTexture.bind();
glBegin(GL_QUADS);
forgeTexture.texCoord(f, 0, 0);
glVertex2f(-fw, -fh);
forgeTexture.texCoord(f, 0, 1);
glVertex2f(-fw, fh);
forgeTexture.texCoord(f, 1, 1);
glVertex2f(fw, fh);
forgeTexture.texCoord(f, 1, 0);
glVertex2f(fw, -fh);
glEnd();
glDisable(GL_TEXTURE_2D);
// We use mutex to indicate safely to the main thread that we're taking the display global lock
// So the main thread can skip processing messages while we're updating.
// There are system setups where this call can pause for a while, because the GL implementation
// is trying to impose a framerate or other thing is occurring. Without the mutex, the main
// thread would delay waiting for the same global display lock
mutex.acquireUninterruptibly();
Display.update();
// As soon as we're done, we release the mutex. The other thread can now ping the processmessages
// call as often as it wants until we get get back here again
mutex.release();
if (pause) {
clearGL();
setGL();
}
Display.sync(100);
}
clearGL();
}
private void setColor(int color) {
glColor3ub((byte) ((color >> 16) & 0xFF), (byte) ((color >> 8) & 0xFF), (byte) (color & 0xFF));
}
private void drawBox(int w, int h) {
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(0, h);
glVertex2f(w, h);
glVertex2f(w, 0);
glEnd();
}
private void drawBar(ProgressBar b) {
glPushMatrix();
// title - message
setColor(fontColor);
glScalef(2, 2, 1);
glEnable(GL_TEXTURE_2D);
fontRenderer.drawString(b.getTitle() + " - " + b.getMessage(), 0, 0, 0x000000);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
// border
glPushMatrix();
glTranslatef(0, textHeight2, 0);
setColor(barBorderColor);
drawBox(barWidth, barHeight);
// interior
setColor(barBackgroundColor);
glTranslatef(1, 1, 0);
drawBox(barWidth - 2, barHeight - 2);
// slidy part
setColor(barColor);
// Step can sometimes be 0.
drawBox((barWidth - 2) * (b.getStep() + 1) / (b.getSteps() + 1), barHeight - 2);
// progress text
String progress = "" + b.getStep() + "/" + b.getSteps();
glTranslatef(((float) barWidth - 2) / 2 - fontRenderer.getStringWidth(progress), 2, 0);
setColor(fontColor);
glScalef(2, 2, 1);
glEnable(GL_TEXTURE_2D);
fontRenderer.drawString(progress, 0, 0, 0x000000);
glPopMatrix();
}
private void drawMemoryBar() {
int maxMemory = bytesToMb(Runtime.getRuntime().maxMemory());
int totalMemory = bytesToMb(Runtime.getRuntime().totalMemory());
int freeMemory = bytesToMb(Runtime.getRuntime().freeMemory());
int usedMemory = totalMemory - freeMemory;
float usedMemoryPercent = usedMemory / (float) maxMemory;
glPushMatrix();
// title - message
setColor(fontColor);
glScalef(2, 2, 1);
glEnable(GL_TEXTURE_2D);
fontRenderer.drawString("Memory Used / Total", 0, 0, 0x000000);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
// border
glPushMatrix();
glTranslatef(0, textHeight2, 0);
setColor(barBorderColor);
drawBox(barWidth, barHeight);
// interior
setColor(barBackgroundColor);
glTranslatef(1, 1, 0);
drawBox(barWidth - 2, barHeight - 2);
// slidy part
long time = System.currentTimeMillis();
if (usedMemoryPercent > memoryColorPercent || (time - memoryColorChangeTime > 1000)) {
memoryColorChangeTime = time;
memoryColorPercent = usedMemoryPercent;
}
int memoryBarColor;
if (memoryColorPercent < 0.75f) {
memoryBarColor = memoryGoodColor;
} else if (memoryColorPercent < 0.85f) {
memoryBarColor = memoryWarnColor;
} else {
memoryBarColor = memoryLowColor;
}
setColor(memoryLowColor);
glPushMatrix();
glTranslatef((barWidth - 2) * (totalMemory) / (maxMemory) - 2, 0, 0);
drawBox(2, barHeight - 2);
glPopMatrix();
setColor(memoryBarColor);
drawBox((barWidth - 2) * (usedMemory) / (maxMemory), barHeight - 2);
// progress text
String progress = getMemoryString(usedMemory) + " / " + getMemoryString(maxMemory);
glTranslatef(((float) barWidth - 2) / 2 - fontRenderer.getStringWidth(progress), 2, 0);
setColor(fontColor);
glScalef(2, 2, 1);
glEnable(GL_TEXTURE_2D);
fontRenderer.drawString(progress, 0, 0, 0x000000);
glPopMatrix();
}
private String getMemoryString(int memory) {
return StringUtils.leftPad(Integer.toString(memory), 4, ' ') + " MB";
}
private void setGL() {
lock.lock();
try {
Display.getDrawable().makeCurrent();
} catch (LWJGLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
glClearColor((float) ((backgroundColor >> 16) & 0xFF) / 0xFF, (float) ((backgroundColor >> 8) & 0xFF) / 0xFF, (float) (backgroundColor & 0xFF) / 0xFF, 1);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
private void clearGL() {
Minecraft mc = Minecraft.getMinecraft();
mc.displayWidth = Display.getWidth();
mc.displayHeight = Display.getHeight();
mc.resize(mc.displayWidth, mc.displayHeight);
glClearColor(1, 1, 1, 1);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, .1f);
try {
Display.getDrawable().releaseContext();
} catch (LWJGLException e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
lock.unlock();
}
}
});
thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
FMLLog.log(Level.ERROR, e, "Splash thread Exception");
threadError = e;
}
});
thread.start();
checkThreadState();
}
use of java.lang.Thread.UncaughtExceptionHandler in project jstorm by alibaba.
the class AsyncLoopThread method init.
private void init(RunnableCallback afn, boolean daemon, RunnableCallback kill_fn, int priority, boolean start) {
if (kill_fn == null) {
kill_fn = new AsyncLoopDefaultKill();
}
Runnable runnable = new AsyncLoopRunnable(afn, kill_fn);
thread = new Thread(runnable);
String threadName = afn.getThreadName();
if (threadName == null) {
threadName = afn.getClass().getSimpleName();
}
thread.setName(threadName);
thread.setDaemon(daemon);
thread.setPriority(priority);
thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
LOG.error("UncaughtException", e);
JStormUtils.halt_process(1, "UncaughtException");
}
});
this.afn = afn;
if (start) {
thread.start();
}
}
use of java.lang.Thread.UncaughtExceptionHandler in project Android-Error-Reporter by tomquist.
the class ExceptionReporter method register.
/**
* Registers this context and returns an error handler object
* to be able to manually report errors.
*
* @param context The context
* @return The error handler which can be used to manually report errors
*/
public static ExceptionReporter register(Context context) {
UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
if (handler instanceof Handler) {
Handler errHandler = (Handler) handler;
errHandler.errorHandler.setContext(context);
return errHandler.errorHandler;
} else {
ExceptionReporter errHandler = new ExceptionReporter(handler, context);
Thread.setDefaultUncaughtExceptionHandler(errHandler.handler);
return errHandler;
}
}
use of java.lang.Thread.UncaughtExceptionHandler in project spring-boot by spring-projects.
the class SilentExitExceptionHandler method setup.
public static void setup(Thread thread) {
UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
if (!(handler instanceof SilentExitExceptionHandler)) {
handler = new SilentExitExceptionHandler(handler);
thread.setUncaughtExceptionHandler(handler);
}
}
use of java.lang.Thread.UncaughtExceptionHandler in project android_frameworks_base by DirtyUnicorns.
the class UiAutomatorTestRunner method run.
public void run(List<String> testClasses, Bundle params, boolean debug, boolean monkey) {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e(LOGTAG, "uncaught exception", ex);
Bundle results = new Bundle();
results.putString("shortMsg", ex.getClass().getName());
results.putString("longMsg", ex.getMessage());
mWatcher.instrumentationFinished(null, 0, results);
// bailing on uncaught exception
System.exit(EXIT_EXCEPTION);
}
});
mTestClasses = testClasses;
mParams = params;
mDebug = debug;
mMonkey = monkey;
start();
System.exit(EXIT_OK);
}
Aggregations