Update GlfwWindow#setIcons logging

This commit is contained in:
JeremyStar™ 2024-10-16 13:21:54 +02:00
parent 665ea05041
commit 8b512d69ae
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -357,8 +357,6 @@ public final class GlfwWindow extends Window {
@ApiStatus.Experimental
@Override
public void setIcons(@NotNull Path @Nullable [] icons) {
getLogger().warn("GlfwWindow#setIcons is experimental and may cause engine or JVM crashes. Here be dragons!");
// Ensure the window is not terminated
if (isTerminated())
return;
@ -366,7 +364,8 @@ public final class GlfwWindow extends Window {
this.icons = icons;
if (icons != null)
try (GLFWImage.Buffer iconsBuffer = GLFWImage.malloc(icons.length)) {
getLogger().diag("GlfwWindow#setIcons » icons.length = " + icons.length);
getLogger().warn("GlfwWindow#setIcons is experimental and may cause engine or JVM crashes. Here be dragons!");
getLogger().diag("icons.length = " + icons.length);
List<ByteBuffer> iconBuffers = new ArrayList<>();
IntBuffer width = MemoryUtil.memAllocInt(1);
@ -374,9 +373,9 @@ public final class GlfwWindow extends Window {
IntBuffer channels = MemoryUtil.memAllocInt(1);
for (Path filepath : icons) {
getLogger().diag("GlfwWindow#setIcons » iterating icons » " + iconBuffers.size() + " » " + filepath);
getLogger().diag("iterating icons » " + iconBuffers.size() + " » " + filepath);
// Load icon
getLogger().diag("GlfwWindow#setIcons » loading icon");
getLogger().diag("loading icon");
iconBuffers.add(STBImage.stbi_load(filepath.toAbsolutePath().toString(), width, height, channels, 4));
if (iconBuffers.getLast() == null) {
@ -385,33 +384,31 @@ public final class GlfwWindow extends Window {
}
// Save into 'iconsBuffer'
getLogger().diag("GlfwWindow#setIcons » saving into buffer");
getLogger().diag("saving into buffer");
iconsBuffer
.position(iconsBuffer.position() + 1)
.width(width.get(0))
.height(height.get(0))
.pixels(iconBuffers.getLast());
}
getLogger().diag("GlfwWindow#setIcons » out of iteration");
getLogger().diag("out of iteration");
// Set icons
getLogger().diag("GlfwWindow#setIcons » setting position");
getLogger().diag("setting position");
iconsBuffer.position(0);
getLogger().diag("GlfwWindow#setIcons » setting icons");
getLogger().diag("setting icons");
Logger.flushLogMessages();
glfwSetWindowIcon(identifierLong, iconsBuffer);
// Free icons
getLogger().diag("GlfwWindow#setIcons » freeing icons");
getLogger().diag("freeing icons");
for (ByteBuffer buffer : iconBuffers)
if (buffer != null) {
getLogger().diag("GlfwWindow#setIcons » freeing buffer");
getLogger().diag("freeing buffer");
STBImage.stbi_image_free(buffer);
} else
getLogger().diag("GlfwWindow#setIcons » skipping null buffer");
getLogger().diag("skipping null buffer");
}
else
getLogger().diag("GlfwWindow#setIcons » icons is null");
}
/** {@inheritDoc} */