forked from StarOpenSource/Engine
Update GlfwWindow#setIcons logging
This commit is contained in:
parent
665ea05041
commit
6d7701a7c3
1 changed files with 11 additions and 14 deletions
|
@ -357,8 +357,6 @@ public final class GlfwWindow extends Window {
|
||||||
@ApiStatus.Experimental
|
@ApiStatus.Experimental
|
||||||
@Override
|
@Override
|
||||||
public void setIcons(@NotNull Path @Nullable [] icons) {
|
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
|
// Ensure the window is not terminated
|
||||||
if (isTerminated())
|
if (isTerminated())
|
||||||
return;
|
return;
|
||||||
|
@ -366,7 +364,8 @@ public final class GlfwWindow extends Window {
|
||||||
this.icons = icons;
|
this.icons = icons;
|
||||||
if (icons != null)
|
if (icons != null)
|
||||||
try (GLFWImage.Buffer iconsBuffer = GLFWImage.malloc(icons.length)) {
|
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<>();
|
List<ByteBuffer> iconBuffers = new ArrayList<>();
|
||||||
IntBuffer width = MemoryUtil.memAllocInt(1);
|
IntBuffer width = MemoryUtil.memAllocInt(1);
|
||||||
|
@ -374,9 +373,9 @@ public final class GlfwWindow extends Window {
|
||||||
IntBuffer channels = MemoryUtil.memAllocInt(1);
|
IntBuffer channels = MemoryUtil.memAllocInt(1);
|
||||||
|
|
||||||
for (Path filepath : icons) {
|
for (Path filepath : icons) {
|
||||||
getLogger().diag("GlfwWindow#setIcons » iterating icons » " + iconBuffers.size() + " » " + filepath);
|
getLogger().diag("iterating icons » " + iconBuffers.size() + " » " + filepath);
|
||||||
// Load icon
|
// Load icon
|
||||||
getLogger().diag("GlfwWindow#setIcons » loading icon");
|
getLogger().diag("loading icon");
|
||||||
iconBuffers.add(STBImage.stbi_load(filepath.toAbsolutePath().toString(), width, height, channels, 4));
|
iconBuffers.add(STBImage.stbi_load(filepath.toAbsolutePath().toString(), width, height, channels, 4));
|
||||||
|
|
||||||
if (iconBuffers.getLast() == null) {
|
if (iconBuffers.getLast() == null) {
|
||||||
|
@ -385,33 +384,31 @@ public final class GlfwWindow extends Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save into 'iconsBuffer'
|
// Save into 'iconsBuffer'
|
||||||
getLogger().diag("GlfwWindow#setIcons » saving into buffer");
|
getLogger().diag("saving into buffer");
|
||||||
iconsBuffer
|
iconsBuffer
|
||||||
.position(iconsBuffer.position() + 1)
|
.position(iconsBuffer.position() + 1)
|
||||||
.width(width.get(0))
|
.width(width.get(0))
|
||||||
.height(height.get(0))
|
.height(height.get(0))
|
||||||
.pixels(iconBuffers.getLast());
|
.pixels(iconBuffers.getLast());
|
||||||
}
|
}
|
||||||
getLogger().diag("GlfwWindow#setIcons » out of iteration");
|
getLogger().diag("out of iteration");
|
||||||
|
|
||||||
// Set icons
|
// Set icons
|
||||||
getLogger().diag("GlfwWindow#setIcons » setting position");
|
getLogger().diag("setting position");
|
||||||
iconsBuffer.position(0);
|
iconsBuffer.position(0);
|
||||||
getLogger().diag("GlfwWindow#setIcons » setting icons");
|
getLogger().diag("setting icons");
|
||||||
Logger.flushLogMessages();
|
Logger.flushLogMessages();
|
||||||
glfwSetWindowIcon(identifierLong, iconsBuffer);
|
glfwSetWindowIcon(identifierLong, iconsBuffer);
|
||||||
|
|
||||||
// Free icons
|
// Free icons
|
||||||
getLogger().diag("GlfwWindow#setIcons » freeing icons");
|
getLogger().diag("freeing icons");
|
||||||
for (ByteBuffer buffer : iconBuffers)
|
for (ByteBuffer buffer : iconBuffers)
|
||||||
if (buffer != null) {
|
if (buffer != null) {
|
||||||
getLogger().diag("GlfwWindow#setIcons » freeing buffer");
|
getLogger().diag("freeing buffer");
|
||||||
STBImage.stbi_image_free(buffer);
|
STBImage.stbi_image_free(buffer);
|
||||||
} else
|
} else
|
||||||
getLogger().diag("GlfwWindow#setIcons » skipping null buffer");
|
getLogger().diag("skipping null buffer");
|
||||||
}
|
}
|
||||||
else
|
|
||||||
getLogger().diag("GlfwWindow#setIcons » icons is null");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
Loading…
Reference in a new issue