Prevent crashing during getQuads by 1. only calling OpenGL stuff if we have a context, 2. also checking that the Tesselator isDrawing.
@@ -27,6 +27,7 @@ import mekanism.client.render.ctm.CTMModelFactory;
import mekanism.client.render.tileentity.RenderBin;
import mekanism.client.render.tileentity.RenderEnergyCube;
import mekanism.client.render.tileentity.RenderFluidTank;
+import mekanism.common.Mekanism;
import mekanism.common.MekanismItems;
import mekanism.common.SideData.IOState;
import mekanism.common.Tier.EnergyCubeTier;
@@ -70,6 +71,7 @@ import net.minecraftforge.fluids.Fluid;
import org.apache.commons.lang3.tuple.Pair;
import org.lwjgl.opengl.GL11;
+import org.lwjgl.opengl.GLContext;
public class BakedCustomItemModel implements IBakedModel, IPerspectiveAwareModel
{
@@ -424,13 +426,23 @@ public class BakedCustomItemModel implements IBakedModel, IPerspectiveAwareModel
}
Tessellator tessellator = Tessellator.getInstance();
+ List<BakedQuad> generalQuads = new LinkedList<BakedQuad>();
+
+ //Test if the current thread has a Context loaded (we don't use it so no need to import its type)
+ Object contextCapabilities;
+ try {
+ contextCapabilities = GLContext.getCapabilities();
+ } catch (RuntimeException e){
+ contextCapabilities = null;
+ }
+
+ if (contextCapabilities != null && MekanismRenderer.isDrawing(tessellator)) {
+ try {
VertexFormat prevFormat = null;
int prevMode = -1;
MekanismRenderer.pauseRenderer(tessellator);
- List<BakedQuad> generalQuads = new LinkedList<BakedQuad>();
-
GlStateManager.pushMatrix();
GlStateManager.translate(0.5F, 0.5F, 0.5F);
GlStateManager.rotate(180, 0.0F, 1.0F, 0.0F);
@@ -445,6 +457,10 @@ public class BakedCustomItemModel implements IBakedModel, IPerspectiveAwareModel
GlStateManager.popMatrix();
MekanismRenderer.resumeRenderer(tessellator);
+ } catch (Throwable t) {
+ Mekanism.logger.error("Error caught in CustomItemModel", t);
+ }
+ }
if(Block.getBlockFromItem(stack.getItem()) != null)
{
