Hello Guest

Recent Posts

Pages: [1] 2 3 ... 10
1
OpenGL / Re: GL.createCapabilities() leaking memory
« Last post by maxhawaii on January 23, 2019, 12:29:41 »
Hey maxhawaii,

You need to call GL.setCapabilities(null) when the current OpenGL context of a thread is cleared, which happens when you call glfwMakeContextCurrent(NULL) or glfwDestroyWindow(handle).

Hi spasi, thank you for your quick reply -- that solved it!
2
OpenGL / Re: GL.createCapabilities() leaking memory
« Last post by spasi on January 23, 2019, 09:40:10 »
Hey maxhawaii,

You need to call GL.setCapabilities(null) when the current OpenGL context of a thread is cleared, which happens when you call glfwMakeContextCurrent(NULL) or glfwDestroyWindow(handle).
3
OpenGL / GL.createCapabilities() leaking memory
« Last post by maxhawaii on January 22, 2019, 15:10:27 »
Hi,

First of all, thank you for a great and powerful library!

I turned on
Code: [Select]
Configuration.DEBUG_MEMORY_ALLOCATOR.set(true); and it is reporting a memory leak related to the GLCapabilities object returned by GL.createCapabilities().

Quote
[LWJGL] 1872 bytes leaked, thread 1 (main), address: 0x7FA9341B7800
   at org.lwjgl.system.ThreadLocalUtil.setEnv(ThreadLocalUtil.java:164)
   at org.lwjgl.opengl.GL.setCapabilities(GL.java:242)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:467)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:321)
   at dk.kollision.motor.misc.Window.createWindow(Window.java:52)
   at dk.kollision.motor.Main.main(Main.java:81)

However, I haven't been able to find any information on how or when to free this object. What am I missing?

Here's the code for my Window class:

Code: [Select]
package dk.kollision.motor.misc;

import dk.kollision.motor.Main;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;

import static org.lwjgl.glfw.Callbacks.glfwFreeCallbacks;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL20.GL_POINT_SPRITE;
import static org.lwjgl.opengl.GL20.GL_VERTEX_PROGRAM_POINT_SIZE;
import static org.lwjgl.system.MemoryUtil.NULL;

public class Window {

    private int id;
    public long handle;

    public int width, height;
    public int framebufferWidth, framebufferHeight;

    private GLFWKeyCallbackI keyCallback;
    private GLFWCursorPosCallbackI cursorPosCallback;
    private GLFWMouseButtonCallbackI mouseButtonCallback;
    private GLFWWindowSizeCallbackI windowSizeCallback;
    private GLFWFramebufferSizeCallbackI framebufferSizeCallback;

    private GLCapabilities capabilities;

    public void createWindow(int id, int width, int height, long pointerToMonitor, long pointerToFirstWindow){
        this.id = id;
        this.width = width;
        this.height = height;

        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
        glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
        //glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, GLFW_RELEASE_BEHAVIOR_NONE);

        handle = glfwCreateWindow(this.width, this.height, "House Of Green", pointerToMonitor, pointerToFirstWindow);
        if ( handle == NULL )
            throw new RuntimeException("Failed to create the GLFW window");


        glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

        glfwMakeContextCurrent(handle);

        capabilities = GL.createCapabilities();

        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_POINT_SPRITE);
        glClearColor(0.0f, 0.0f, 0.0f, 0);

        glfwSwapInterval(1);

        fetchFramebufferDimensions();

        glfwShowWindow(handle);
    }

    public void focus(){
        glfwFocusWindow(handle);
    }

    public void hideWindow(){
        glfwHideWindow(handle);
    }

    public void destroyWindow(){
        glfwFreeCallbacks(handle);
        glfwDestroyWindow(handle);
        GL.destroy();
    }

    public void registerCallbacks(){
        keyCallback = (window, key, scancode, action, mods) -> {
            if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE ) {
                glfwSetWindowShouldClose(window, true);
            } else {
                boolean shift = (mods & GLFW_MOD_SHIFT) != 0;
                boolean alt = (mods & GLFW_MOD_ALT) != 0;
                boolean ctrl = (mods & GLFW_MOD_CONTROL) != 0;

                if(action == GLFW_RELEASE){
                    Main.onKeyReleased(window, key, action, shift, alt, ctrl);
                } else if(action == GLFW_PRESS) {
                    Main.onKeyPressed(window, key, action, shift, alt, ctrl);
                }
            }
        };
        glfwSetKeyCallback(handle, keyCallback);

        cursorPosCallback = (window, xpos, ypos) -> {
            double mouseX = xpos / width;
            double mouseY = ypos / height;
            Main.onMouseMoved(id, mouseX, mouseY);
        };
        glfwSetCursorPosCallback(handle, cursorPosCallback);

        mouseButtonCallback = (window, button, action, mods) -> {
            boolean mousePressed = (button == GLFW_MOUSE_BUTTON_1) && (action == GLFW_PRESS);
            if(mousePressed){
                Main.onMousePressed();
            } else {
                Main.onMouseReleased();
            }
        };
        glfwSetMouseButtonCallback(handle, mouseButtonCallback);

        windowSizeCallback = (window, w, h) -> {
            width = w;
            height = h;
        };
        glfwSetWindowSizeCallback(handle, windowSizeCallback);

        framebufferSizeCallback = (window, w, h) -> {
            framebufferWidth = w;
            framebufferHeight = h;
        };
        glfwSetFramebufferSizeCallback(handle, framebufferSizeCallback);
    }

    public void prepareRendering(){

        glfwMakeContextCurrent(handle);

        GL.setCapabilities(capabilities);
    }

    public void fetchFramebufferDimensions(){

        int[] widthBuffer = new int[1];
        int[] heightBuffer = new int[1];

        glfwMakeContextCurrent(handle);

        glfwGetFramebufferSize(handle, widthBuffer, heightBuffer);

        framebufferWidth = widthBuffer[0];
        framebufferHeight = heightBuffer[0];
    }
}

Sincerely,
4
Vulkan / Re: Vulkan - Nuklear
« Last post by ealrann on January 17, 2019, 13:59:08 »
I finally made it work. Here the code around that if somebody is interested (but there is an heavy abstraction behind that).
https://github.com/Ealrann/VSand/tree/190117_SAND_V1.1.0/org.sheepy.vulkan.nuklear/src/main/java/org/sheepy/vulkan/nuklear/pipeline

The main point with vulkan is: you need to know what texture you will have to use before drawing, to prepare your descriptorSets. You cannot just bind what nuklearCmd.texture() returns during the draw (as you would do in OpenGL).
What I finally understood, is that the nuklearCmd.texture() are simply the nullTexture, and the fontTexture (maybe more for images, but I don't use them for now), so I just built these two descriptors when I allocate the graphic pipeline.

I have to say, if you could unlock the bake part of nuklear, it would be great  ;D. But I understand that you don't want the stb's nuklear dependencies in LWJGL (and I prefer LWJGL stays light).
5
Vulkan / Re: VSand
« Last post by ealrann on January 17, 2019, 13:45:25 »
New version with notable changes:
- Using now Nuklear for UI (with the LWJGL binding)
- Java is no longer required for the user, I build with JLink.

https://github.com/Ealrann/VSand/releases/tag/190117_SAND_V1.1.0
6
Bug Reports / RFE / Re: [SOLVED] JVM crashes on repeated calls to glTexImage2D
« Last post by spasi on January 13, 2019, 23:14:13 »
Hmm, sounds like JDK-8167409. LWJGL skips Critical Natives for affected functions on Linux & macOS, but functions like glTexImage2D are not in that set. Could you please try with Java 10 or 11 (without -XX:-CriticalJNINatives) to see if the issue is indeed resolved?
7
OpenGL / openGL capabilitises not working got error how do i fix it?
« Last post by pheonixfirewingz on January 13, 2019, 16:22:20 »
Exception in thread "main" java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:378)
   at org.lwjgl.opengl.GL.createCapabilities(GL.java:322)
   at enigne.Display.create(Display.java:63)
   at wolfenginetestgame.WolfEngineTestGame.loadgame(WolfEngineTestGame.java:42)
   at wolfenginetestgame.WolfEngineTestGame.main(WolfEngineTestGame.java:18)

-------------------------------Code-----------------------------------------------------------------------------------
package enigne;

import enigne.utils.Utils;
import enigne.utils.math.Vector3f;

import java.nio.DoubleBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;

public class Display
{
    private static int width = ((int)java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth()) - 200,
          height = (width / 16) * 9;
    private static long displayID;
    private static String title;
    @SuppressWarnings("unused")
   private double fps_Max, time , unprocessedTime = 0, processedTime;
    private boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST],
          mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
    //temp
    private Vector3f color = new Vector3f(0.0F,0.0F,0.0F);
   
    @SuppressWarnings("static-access")
   public Display(String title,int fps)
    {
       this.fps_Max = 1.0/fps;
        this.title = title;
    }
   
    @SuppressWarnings("unused")
   public void create()
    {
        if(GLFW.glfwInit() == false)
        {
            Utils.engineError("GLFW failed to load", "could not boot right and returned false");
            System.exit(-1);
        }
        displayID = GLFW.glfwCreateWindow(width, height, title, 0, 0);
         if(displayID == 0)
        {
            Utils.engineError("failed to Create display", "check display class");
            System.exit(-1);
        }     
         GLFW.glfwMakeContextCurrent(displayID);
         
         GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
         GLFW.glfwSetWindowPos(displayID, (width / 12), (height / 10));
         
         GLFW.glfwShowWindow(displayID);
         GL.createCapabilities();
         
         time = getTime();
         
    }
   
    public void bufferSwap()
    {
       GLFW.glfwSwapBuffers(displayID);
    }
   
    //-------------------start--IO-----------------------------------
   
    public boolean getKeyDown(int KeyDown)
    {
       return GLFW.glfwGetKey(displayID, KeyDown) == 1;
    }
   
    public boolean getMouseDown(int MouseButton)
    {
       return GLFW.glfwGetMouseButton(displayID, 0) == 1;
    }
   
    public boolean isKeyDown(int keyCode)
    {
       return getKeyDown(keyCode) && keys[keyCode];
    }
   
    public boolean isKeyReleased(int keyCode)
    {
       return !getKeyDown(keyCode) && keys[keyCode];
    }
   
    public boolean isMouseButtonDown(int keyCode)
    {
       return getMouseDown(keyCode) && mouseButtons[keyCode];
    }
   
    public boolean isMouseButtonReleased(int keyCode)
    {
       return !isMouseButtonDown(keyCode) && mouseButtons[keyCode];
    }
   
    public double getMouseXPos()
    {
       DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
       GLFW.glfwGetCursorPos(displayID, buffer, null);
       return buffer.get(0);
       
    }
   
    public double getMouseYPos()
    {
       DoubleBuffer buffer = BufferUtils.createDoubleBuffer(1);
       GLFW.glfwGetCursorPos(displayID, null, buffer);
       return buffer.get(0);
       
    }
   
    //-------------------end--IO---------------------------------------
   
    //-------------------FPS--CONTROL----------------------------------
    public double getTime()
    {
       return System.nanoTime() / 1000000000;
    }
   
    public boolean shouldUpdate()
    {
       double nextTime = getTime();
       double passedTime = nextTime - time;
       processedTime += passedTime;
       time = nextTime;
       while (processedTime > fps_Max)
       {
          processedTime -= fps_Max;
          return true;
       }
       return false;
    }
    //-------------END--FPS--CONTROL-------------------------------------
    public void update(int fps)
    {
       if(!(fps <= 30))
       {
       fps_Max = 1.0/fps;
       }
       for(int i = 0; i < GLFW.GLFW_KEY_LAST; i++)
       {
          keys = isKeyDown(i);
       }
       for(int i = 0; i < GLFW.GLFW_MOUSE_BUTTON_LAST; i++)
       {
          mouseButtons = isMouseButtonDown(i);
       }
       GL11.glClearColor(color.x,color.y , color.z, 1.0F);
       GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
       GLFW.glfwPollEvents();
    }
   
    public boolean close()
    {
        return GLFW.glfwWindowShouldClose(displayID);
    }

   public static int getWidth() {
      return width;
   }

   public static int getHeight() {
      return height;
   }

   public static long getDisplayID() {
      return displayID;
   }

   public static String getTitle() {
      return title;
   }   
   
   
}
8
Bug Reports / RFE / [SOLVED] JVM crashes on repeated calls to glTexImage2D
« Last post by lscosta on January 12, 2019, 14:43:04 »
The JVM flag did the trick! Thank you so much.
9
Bug Reports / RFE / Re: [BUG] JVM crashes on repeated calls to glTexImage2D
« Last post by spasi on January 12, 2019, 09:53:03 »
Hey Lael,

Getting a crash after a certain number of calls suggests an issue related to GC or JIT compilation. You could try the following:

- Run your application as is with -XX:-CriticalJNINatives.
- Replace the data array with a FloatBuffer.

Is the crash fixed with either option?
10
Bug Reports / RFE / [SOLVED] JVM crashes on repeated calls to glTexImage2D
« Last post by lscosta on January 12, 2019, 07:48:43 »
Hi!
I am working on a fluid simulation that involves updating a GL texture frequently (say, every frame). I have a float[] whose contents I mutate before calling glTexImage2D(). I'm not exactly what flavor of problem I am experiencing (error on my part? JVM/system bug? LWJGL issue?), but the symptom is that my program works correctly for several seconds, then the JVM crashes. My hunch is that some memory is being mismanaged (again, not sure if it's by me/Java/LWJGL). Here are some of my thoughts so far:

  • I've counted and it seems to take the same number of calls to reach the crash every time: the 384th call causes a SIGSEGV. This does not seem to vary with the dimensions of the texture.
  • GL does not report an error immediately before or after any of the calls.
  • Since the content I am attempting to upload is generated randomly, I don't think this issue is dependent on the data passed in.
  • I develop using IntelliJ IDEA Ultimate. If I have IntelliJ generate a JAR and then run in from the command line, the issue persists. I haven't yet tried compiling from scratch (lotsa dependencies, y'know).

Here's a pared down version of my code. It's spread across several files, so I'll just paste the relevant bits here but if it would help I can put in more detail later. There's also an error log file attached.

My Texture class:
Code: [Select]
package graphics;
import org.joml.Vector4f;
import java.util.Arrays;

import static org.lwjgl.opengl.GL41.*;

public class Texture {
    private int width;
    private int height;
    private int textureID;
    private int textureUnit;
    private float[] data;

    public Texture(int width, int height, int textureUnit) {
        this.textureUnit = textureUnit;
        this.width = width;
        this.height = height;
        this.data = new float[width * height * 4];
        Arrays.fill(this.data, 0.f);

        textureID = glGenTextures();
        bind();
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

        pushToGL();

        unbind();
        checkError();
    }

    private void checkError() {
        int error = glGetError();
        if (error != GL_NO_ERROR) {
            System.out.println("Error: " + error);
        }
    }

    public void pushToGL() {
        checkError();
        // this seems to be the problem, doc:
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, data);
        checkError();
    }

    public void setPixel(int x, int y, float r, float g, float b, float a) {
        if (x < 0 || x >= width || y < 0 || y >= height)
            throw new IndexOutOfBoundsException();
        else {
            int index = 4 * (x + y * width);
            data[index] = r;
            data[index + 1] = g;
            data[index + 2] = b;
            data[index + 3] = a;
        }
    }

    public void setPixel(int x, int y, Vector4f color) {
        if (x < 0 || x >= width || y < 0 || y >= height)
            throw new IndexOutOfBoundsException();
        else {
            int index = 4 * (x + y * width);
            data[index] = color.x;
            data[index + 1] = color.y;
            data[index + 2] = color.z;
            data[index + 3] = color.w;
        }
    }

    public Vector4f getPixel(int x, int y) {
        if (x < 0 || x >= width || y < 0 || y >= height)
            throw new IndexOutOfBoundsException();
        else {
            int index = 4 * (x + y * width);
            return new Vector4f(data[index],
                    data[index + 1],
                    data[index + 2],
                    data[index + 3]);
        }
    }

    public void bind() {
        glActiveTexture(textureUnit);
        glBindTexture(GL_TEXTURE_2D, textureID);
    }

    public void unbind() {
        glBindTexture(GL_TEXTURE_2D, 0);
    }

    // also some getters...
}

Here's the caller:
Code: [Select]
import graphics.Shader;

import java.io.IOException;

public class OasisWindow extends Fenster {

    private Shader geometryShader;
    private PoolShape poolShape;
    private CausticShape causticShape; // thing that owns a texture

    public OasisWindow() {
        windowTitle = "Oasis";
    }

    @Override
    protected void preLoop() { // this gets run once after the GL context exists
        // create texture
        try {
            geometryShader = new Shader("res/shaders/preview.vert", "res/shaders/preview.frag");
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
        poolShape = new PoolShape();
        causticShape = new CausticShape(poolShape);
        geometryShader.bind();
        geometryShader.setUniform("tex", 0);
        causticShape.causticTexture.bind(); // only the one texture so bind it at the start
    }

    @Override
    protected void loopBody(float dt) { // this gets run in the glfw loop
        poolShape.frame(dt);
        causticShape.update(); // calls Texture::setPixel() a bunch of times
        causticShape.causticTexture.pushToGL(); // this is the problem

        defaultCameraUpdate(dt);
        applyDefaultCamera(geometryShader);

        poolShape.draw(geometryShader);
        causticShape.draw(geometryShader);
    }

    // there's also some cleanup code but the JVM helps me out by crashing first!
}

Thank you very much for your time!
-Lael

Pages: [1] 2 3 ... 10