Skip to content

Commit

Permalink
Create crash report instead of logging severe render errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Apr 5, 2017
1 parent 9fd9d1a commit dbd065e
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/main/java/mezz/jei/gui/ingredients/GuiIngredientFast.java
Expand Up @@ -30,8 +30,12 @@
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.crash.ICrashReportDetail;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.ForgeHooksClient;
Expand Down Expand Up @@ -87,13 +91,12 @@ public void renderItemAndEffectIntoGUI() {
return;
}

ItemStack itemStack = (ItemStack) ingredient;
final ItemStack itemStack = (ItemStack) ingredient;

try {
renderItemAndEffectIntoGUI(itemStack);
} catch (RuntimeException e) {
logRenderError(this, e);
clear();
throw createRenderIngredientException(e, itemStack);
}
}

Expand Down Expand Up @@ -169,8 +172,7 @@ public void renderSlow() {
try {
renderSlow(ingredient, area, padding);
} catch (RuntimeException e) {
logRenderError(this, e);
clear();
throw createRenderIngredientException(e, ingredient);
}
}
}
Expand All @@ -194,8 +196,7 @@ public void renderOverlay(Minecraft minecraft) {
try {
renderOverlay(minecraft, itemStack);
} catch (RuntimeException e) {
logRenderError(this, e);
clear();
throw createRenderIngredientException(e, itemStack);
}
}

Expand Down Expand Up @@ -357,19 +358,22 @@ private static <V> List<String> getTooltip(Minecraft minecraft, V ingredient, II
return list;
}

private static void logRenderError(GuiIngredientFast guiItemStack, Exception e) {
Object ingredient = guiItemStack.getIngredient();
logRenderError(ingredient, e);
}

private static <V> void logRenderError(@Nullable V ingredient, Exception e) {
if (ingredient == null) {
Log.error("Rendering ingredient crashed.", e);
} else {
IIngredientRegistry ingredientRegistry = Internal.getIngredientRegistry();
IIngredientHelper<V> ingredientHelper = ingredientRegistry.getIngredientHelper(ingredient);
String info = ingredientHelper.getErrorInfo(ingredient);
Log.error("Rendering ingredient crashed: {}", info, e);
}
private static <T> ReportedException createRenderIngredientException(Throwable throwable, final T ingredient) {
final IIngredientHelper<T> ingredientHelper = Internal.getIngredientRegistry().getIngredientHelper(ingredient);
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Rendering ingredient");
CrashReportCategory crashreportcategory = crashreport.makeCategory("Ingredient being rendered");
crashreportcategory.setDetail("Ingredient Mod", new ICrashReportDetail<String>() {
@Override
public String call() throws Exception {
return Internal.getModIdUtil().getModNameForIngredient(ingredient, ingredientHelper);
}
});
crashreportcategory.setDetail("Ingredient Info", new ICrashReportDetail<String>() {
@Override
public String call() throws Exception {
return ingredientHelper.getErrorInfo(ingredient);
}
});
throw new ReportedException(crashreport);
}
}

0 comments on commit dbd065e

Please sign in to comment.