mojira.dev
MC-121714

Unable to save screenshots and world icons if the path contains non-ASCII characters

The bug

Taking a screenshot fails when the folder of your game profile contains non-ASCII characters.

18w06a

[22:40:50] [Client thread/WARN]: Couldn't save screenshot
java.io.IOException: Could not write image to the PNG file "###\screenshots\2018-02-11_22.40.50.png": Corrupt JPEG
	at csp.a(SourceFile:306) ~[18w06a.jar:?]
	at bxc.a(SourceFile:45) ~[18w06a.jar:?]
	at bxc.a(SourceFile:30) ~[18w06a.jar:?]
	at bwu.a(SourceFile:256) ~[18w06a.jar:?]
	at org.lwjgl.glfw.GLFWKeyCallbackI.callback(GLFWKeyCallbackI.java:23) [lwjgl-glfw-3.1.2.jar:?]
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.1.2.jar:?]
	at org.lwjgl.glfw.GLFW.glfwPollEvents(GLFW.java:2520) [lwjgl-glfw-3.1.2.jar:?]
	at bwx.b(SourceFile:803) [18w06a.jar:?]
	at bwx.a(SourceFile:383) [18w06a.jar:?]
	at net.minecraft.client.main.Main.main(SourceFile:141) [18w06a.jar:?]

Additionally world icons cannot be saved either.

18w06a

[22:45:42] [Client thread/WARN]: Couldn't save auto screenshot
java.io.IOException: Could not write image to the PNG file "###\saves\New World\icon.png": Corrupt JPEG
	at csp.a(SourceFile:306) ~[18w06a.jar:?]
	at cjr.n(SourceFile:1039) [18w06a.jar:?]
	at cjr.a(SourceFile:949) [18w06a.jar:?]
	at bwx.b(SourceFile:823) [18w06a.jar:?]
	at bwx.a(SourceFile:383) [18w06a.jar:?]
	at net.minecraft.client.main.Main.main(SourceFile:141) [18w06a.jar:?]

Besides the profile name also having non-ascii chars in the world name triggers that issue:

18w20b

java.io.IOException: Could not write image to the PNG file "D:\mc\mn\bugs\.minecraft\saves\����BUG\icon.png": Corrupt JPEG
	at deq.a(SourceFile:306) ~[18w20b.jar:?]
	at cvd.o(SourceFile:870) [18w20b.jar:?]
	at cvd.a(SourceFile:783) [18w20b.jar:?]
	at cht.c(SourceFile:820) [18w20b.jar:?]
	at cht.a(SourceFile:381) [18w20b.jar:?]
	at net.minecraft.client.main.Main.main(SourceFile:144) [18w20b.jar:?]

How to reproduce

  1. Create a folder whose name contains non-ASCII characters, for example the following

    äö²³§ß
  2. Launch Minecraft with this folder as game directory

  3. Try to take a screenshot

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 10

This is weird and should not happen. Can you please attach the game's log files (located in [.minecraft|http://hopper.minecraft.net/help/guides/finding-minecraft-data-folder]/logs)?

  • If you know you haven't started the game since this issue happened, just attach latest.log

  • Otherwise, attach all of the files starting with 2017-11-08 or 2017-11-09.

I found that as soon as I upgraded to this version, there would be problems

Looking at MC-122415, and the screenshots provided by @unknown in this ticket

[media]

, apparently this has todo with non-ascii characters in the path name.
I'm not so sure if MC-121830 is really a duplicate and is possibly caused by something different.

Not fixed. Could reproduce it in 18w06a.

It can also be reproduced in 18w08a and 18w08b.
log:

[12:27:28] [Client thread/WARN]: Couldn't save auto screenshot
java.io.IOException: Could not write image to the PNG file "D:\1.13 snapshot\.minecraft\saves\新的世界\icon.png": Corrupt JPEG
at cuh.a(SourceFile:306) ~[18w08b.jar:?]
at cle.n(SourceFile:1049) [18w08b.jar:?]
at cle.a(SourceFile:962) [18w08b.jar:?]
at bya.b(SourceFile:820) [18w08b.jar:?]
at bya.a(SourceFile:381) [18w08b.jar:?]
at net.minecraft.client.main.Main.main(SourceFile:141)

I meet the same problem. I hope it can be resolved quickly. Using 搜狗输入法 to take a screenshot is not convenient.

Can reproduce in 18w08b.

Analysis:

This is an issue in the stb image library, which is used (via the LWJGL binding) to save screenshots. There is an open pull request to fix this; the fix would also need to be applied to the LWJGL version of the library.

I've tried that myself, and while getting LWJGL to build right was hard, that PR (plus some changes to define UNICODE, because I don't have everything set up right) did allow it to build correctly and fix this issue.

However, there is an issue on the MC end, which is the reason for the "Corrupt JPEG" message despite the game loading a PNG. Using 18w10b obf, in cvf (NativeImage?) on line 305:

if (!STBImageWrite.stbi_write_png(lvt_2_1_.UTF8(p_a_1_, true), this.a(), this.b(), 4, MemoryUtil.memByteBuffer(this.d, this.e), 0)) {
            throw new IOException("Could not write image to the PNG file \"" + p_a_1_ + "\": " + STBImage.stbi_failure_reason());
         }

stb_image_write does not do anything with (and in fact does not know about) general stb_image errors; the message returned from STBImage.stbi_failure_reason is unrelated to the reason why the call to stbi_write_png failed. So the "Corrupt JPEG" message doesn't apply, and the call to stbi_failure_reason should probably be removed.

Perhaps it would also make sense to use stbi_write_png_to_func, and manually handle writing to disk, as that should bypass this unicode issue.

I'm not sure where the "Corrupt JPEG" part comes from, but as a quick note I did build lwjgl_stb.dll with the "non-user-friendly" message mode, and I got "no SOI" instead which indicates an error in stbi__decode_jpeg_header. This is probably from some earlier code, but I don't know which.

陈执一

boq

Confirmed

screenshot, world-icon

Minecraft 17w45a, Minecraft 17w45b, Minecraft 18w06a, Minecraft 18w08b, Minecraft 18w10a, ..., Minecraft 18w15a, Minecraft 18w20c, Minecraft 18w21a, Minecraft 18w22b, Minecraft 18w22c

Minecraft 17w49a, Minecraft 1.13-pre2

Retrieved