TeamJM/journeymap-api

Unable to display images on the map

Closed this issue · 10 comments

This issue has made me attempt numerous times, spending a considerable amount of time without a resolution. It might be due to my technical skills. I hope you could take a look at my code to see if there are any issues.

public static void receivePacketSpecifiedImageOverlay(PacketSpecifiedImageOverlay packetSpecifiedImageOverlay){
        SubResourcesObject subResourcesObject = ResourcesManager.resources.content.get(packetSpecifiedImageOverlay.getUniqueName());
        BufferedImage bufferedImage = getImageByUniqueName(subResourcesObject.uniqueName);
        BlockPos blockPos = new BlockPos(packetSpecifiedImageOverlay.getX(), packetSpecifiedImageOverlay.getY(), packetSpecifiedImageOverlay.getZ());
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        displayImage(bufferedImage); //This is used to test whether the BufferedImage object is exist
        MapImage mapImage = new MapImage(bufferedImage)
                .centerAnchors()
                .setRotation(0)
                .setOpacity(1f);
        String displayId = String.format("image%s,%s,%s,%s", blockPos.getX(), blockPos.getZ(), width, height);
        BlockPos lowerRight = blockPos.add(width, 0, height);
        ImageOverlay imageOverlay = new ImageOverlay(AoitoriMap.MOD_ID, displayId, blockPos, lowerRight, mapImage);
        imageOverlay.setLabel("Image Overlay")
                .setTitle(displayId)
                .setOverlayListener(new SampleImageOverlayFactory.ImageListener(jmAPI, imageOverlay));
        if(jmAPI.playerAccepts(AoitoriMap.MOD_ID, DisplayType.Image)){
            System.out.println("Image enable");
        }
        try {
            jmAPI.show(imageOverlay);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

the version I am using:
journeymap-1.12.2-5.7.1.jar
forge:1.12.2-14.23.5.2860
JM-API version: 1.12.2-1.4-SNAPSHOT

fix the formatting so I can read that please.

fix the formatting so I can read that please.
I am sorry,I am trying to format it.

I am really sorry, I dont know why the formatting becomes strange when I try to adjust it. Here is the following paragraph for your review.The console prints 'Image enable,' but there is no change on the player's map. I have also tried using Marker and Waypoint. While Waypoint can display something, it still does not show the image. Marker behaves the same way, with no change. Occasionally, there are errors in the console, but they seem unrelated to my code. Here is the Java stack trace for the error.

Thank you for your teaching; I can now adjust code formatting.

[02:00:37] [Client thread/ERROR] [journeymap]: Unexpected exception in jm.fullscreen.drawScreen(): java.lang.NullPointerException
	at journeymap.client.api.model.MapImage.getRotation(MapImage.java:329)
	at journeymap.client.render.draw.DrawImageStep.draw(DrawImageStep.java:74)
	at journeymap.client.render.map.GridRenderer.draw(GridRenderer.java:423)
	at journeymap.client.render.map.GridRenderer.draw(GridRenderer.java:409)
	at journeymap.client.ui.fullscreen.Fullscreen.drawMap(Fullscreen.java:1395)
	at journeymap.client.ui.fullscreen.Fullscreen.drawScreen(Fullscreen.java:393)
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:396)
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1124)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119)
	at net.minecraft.client.Minecraft.run(Minecraft.java:398)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.legacydev.Main.start(Main.java:86)
	at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29)

[02:00:37] [Client thread/WARN] [journeymap]: Fullscreen.drawScreen is not running.
[02:00:39] [Client thread/ERROR] [journeymap]: Error during MiniMap.drawMap(): null (SUPPRESSED)
[02:00:39] [Client thread/ERROR] [journeymap]: java.lang.NullPointerException
	at journeymap.client.api.model.MapImage.getRotation(MapImage.java:329)
	at journeymap.client.render.draw.DrawImageStep.draw(DrawImageStep.java:74)
	at journeymap.client.render.map.GridRenderer.draw(GridRenderer.java:423)
	at journeymap.client.render.map.GridRenderer.draw(GridRenderer.java:409)
	at journeymap.client.ui.minimap.MiniMap.drawMap(MiniMap.java:292)
	at journeymap.client.ui.minimap.MiniMap.drawMap(MiniMap.java:174)
	at journeymap.client.ui.UIManager.drawMiniMap(UIManager.java:328)
	at journeymap.client.forge.event.MiniMapOverlayHandler.onRenderOverlay(MiniMapOverlayHandler.java:103)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_31_MiniMapOverlayHandler_onRenderOverlay_RenderGameOverlayEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.client.GuiIngameForge.pre(GuiIngameForge.java:907)
	at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:119)
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1098)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119)
	at net.minecraft.client.Minecraft.run(Minecraft.java:398)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.legacydev.Main.start(Main.java:86)
	at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29)

because you are using a single ` instead of triple.

You may need to add Journeymap as a dependency of your project so you can set breakpoints when running indev where that NPE is happening.

You may need to add Journeymap as a dependency of your project so you can set breakpoints when running indev where that NPE is happening.

Thank you for your guidance, I am currently trying

You may need to add Journeymap as a dependency of your project so you can set breakpoints when running indev where that NPE is happening.

After multiple attempts, I found that this error is not caused by the execution of my code but rather thrown by the JM mod itself. However, it does not impact the functionality of the mod. It occurred once coincidentally after the execution of my code, and even if I comment out my code, the NPE still occurs

does it happen only indev or in production too?

does it happen only indev or in production too?

This error occurred sporadically, and I only tested it in a development environment. This issue might be a false alarm. I directly cloned the GitHub repository of JourneyMap-API. After resolving the error, I mimicked the provided code to create the current code. When I commented out almost all the code in the ExampleJourneymapPlugin class and ForgeEventListener class, this method started working normally. It might be due to a naming conflict with ImageOverlay. I apologize for my problem and appreciate your guidance, which inadvertently helped me resolve the issue.

Alright, sounds good.
If you need more help, please feel free to join our discord too.
I will close this now.