Jump to content

[SOLVED][1.12.2] Rendering code causing hard client crash


Recommended Posts

Posted (edited)

Evening all,

 

Trying my first mod here,  I've got some code that renders a highlight around air blocks.

 

The code works perfectly, until we come across snow covered blocks,  Then it crashes the client with little to no information as to why.  Here is the code, and the error below. (the try catch is just for debugging)

try
        {
            EntityPlayerSP player = Minecraft.getMinecraft().player;
            World world = player.getEntityWorld();

            if (player.getHeldItemMainhand().getItem() == StrapItems.BASIC_STRAP)
            {
                ItemBasicStrap myItem = (ItemBasicStrap) player.getHeldItemMainhand().getItem();
                RayTraceResult tracer = player.rayTrace(myItem.BlockRange, 1.0F);

                BlockPos pos = tracer.getBlockPos();

                GlStateManager.enableBlend();
                GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
                GlStateManager.glLineWidth(3.0F);
                GlStateManager.disableTexture2D();
                GlStateManager.depthMask(false);

                Block state = world.getBlockState(pos).getBlock();

                double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
                double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
                double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();

                RenderGlobal.drawSelectionBoundingBox(state.FULL_BLOCK_AABB.offset(-x, -y, -z).offset(pos).grow(0.002), 1.0F, 1.0F, 1.0F, 0.4F);

                GlStateManager.depthMask(true);
                GlStateManager.enableTexture2D();
                GlStateManager.disableBlend();
            }
        }
        catch (Exception ex)
        {
            logger.info("AIR STRAPS AIR STRAPS AIR STRAPS >> {}", ex.getMessage());
        }

 

Error

  Quote

[20:50:43] [main/ERROR] [FML]: Exception caught during firing event net.minecraftforge.client.event.RenderWorldLastEvent@492f3239:
java.lang.NullPointerException: null
    at com.daten.AirStraps.world.renderHighlights.onRender(renderHighlights.java:60) ~[renderHighlights.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_renderHighlights_onRender_RenderWorldLastEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?]
    at net.minecraftforge.client.ForgeHooksClient.dispatchRenderLast(ForgeHooksClient.java:181) [ForgeHooksClient.class:?]
    at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1485) [EntityRenderer.class:?]
    at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1312) [EntityRenderer.class:?]
    at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1115) [EntityRenderer.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1208) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_201]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_201]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
[20:50:43] [main/ERROR] [FML]: Index: 1 Listeners:
[20:50:43] [main/ERROR] [FML]: 0: NORMAL
[20:50:43] [main/ERROR] [FML]: 1: ASM: class com.daten.AirStraps.world.renderHighlights onRender(Lnet/minecraftforge/client/event/RenderWorldLastEvent;)V
[20:50:43] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Stopping server
[20:50:43] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Saving players
AL lib: (EE) alc_cleanup: 1 device not closed

Expand  

 

Any help would be greatly appreciated!!

 

Edited by DatenThielt
Update Title
Posted
  On 2/16/2019 at 8:48 PM, diesieben07 said:

Little to no information? It tells you exactly what's wrong and on what line. Use the debugger to figure out which value is null and then fix your bug.

Expand  

That's what I get for programming after a few beers.    Thanks for the reality slap.  The try-catch was hiding the original error line, turned out the raytrace could return null over certain blocks.  Fixed and thank you!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When you name a method like that, with no return value, it is a constructor. The constructor must have the same name as the class it constructs, in this case, ModItems. I would strongly advise reading up on some basic Java tutorials, because you will definitely be running into a lot more issues as you go along without the basics. *I should also add that the Forge documentation is a reference, not a tutorial. Even following tutorials, you should know Java basics, otherwise the smallest of mistakes will trip you up as you copy someone elses code.
    • so, I'm starting modding and I'm following the official documantation for forge: https://docs.minecraftforge.net, but in the registries part it is not working as it is in the docs:   public class ModItems { private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DarkStarvation.MOD_ID); public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); public DarkStarvation(FMLJavaModLoadingContext context) { ITEMS.register(context.getModEventBus()); } } in 'public DarkStarvation(...' the DarkStarvation has this error: Invalid method declaration; return type required and the getModEventBus(): Cannot resolve method 'getModEventBus' in 'FMLJavaModLoadingContext' please help, I asked gpt but it is saying that I'm using an old method, but I'm following the latest version of Forge Docs???
    • I merged your second post with the original , there is no need to post a new thread asking for an answer. If someone sees your post and can help, they will reply. If you are seeking a quicker response, you could try asking in the Minecraft Forge diacord.
    • Create a new instance and start with cobblemon - if this works, add the rest of your mods in groups   Maybe another mod is conflicting - like Sodium/Iris or Radical Cobblemon Trainers
    • https://forums.minecraftforge.net/topic/157393-1201-forge-rocket-flame-particle-trail-moves-up-and-crashes-into-the-rocket-during-flight/#comment-584134
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.