kotlin-graphics/imgui

Imgui not compatible with Mac OS 10.11.4 and LibGDX 1.9.9

Closed this issue · 62 comments

Exception in thread “main” com.badlogic.gdx.utils.GdxRuntimeException: java.lang.Exception: ERROR: 0:3: ‘’ :  version ‘150’ is not supported

    at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:117)
    at com.x.prototype.desktop.DesktopLauncher.main(DesktopLauncher.kt:21)
Caused by: java.lang.Exception: ERROR: 0:3: ‘’ :  version ‘150’ is not supported

    at gln.objects.GlShader$Companion.createFromSource-RHQEpZs(shader.kt:70)
    at imgui.impl.ImplGL3.createDeviceObjects(ImplGL3.kt:57)
    at imgui.impl.LwjglGlfw.newFrame(LwjglGlfw.kt:107)

This is not an ImGui issue, per se. You are running an old mac which does not support OpenGL 3.2, which is the minimum version of OpenGL we support. An OpenGL 2 backend might be considered, but is a small use case for most of us. I'll see what I can do

Hm how hard for one would be to make It compatible with opengl2? It is about changing this class https://github.com/kotlin-graphics/imgui/blob/master/src/main/kotlin/imgui/impl/ImplGL3.kt only?

For me myself, this would be hard as my experience is with OpenGL 3 and 4, not 2. It would require making a separate class, ImplGL2, and only using functions up to OpenGL 2.1 in it, and changing the shaders to be OpenGL 2.1 compatible. If you wish to do it, please send a PR when it gets close to workable and I'll see what I can do to help.

On a side note, with the Vulkan backend being worked on, It might not be that far off the path for us to add that ourselves, but having someone send in a PR with it will be much faster.

I'm gonna give this an attempt in the ImplGL2 branch. We'll see what comes of it

OpenGL2 support is live in the ImplGL2 branch. Give it a shot and see if it works for you.

Thanks for your effort!
So I have changed It like this:

LwjglGlfw.init(
GlfwWindow.from((Gdx.graphics as Lwjgl3Graphics).window.windowHandle),
clientApi_ = LwjglGlfw.GlfwClientApi.OpenGL2
)

ImplGL3.renderDrawData(this) => LwjglGlfw.instance.renderDrawData(this)
And It shows up this error:

0(12) : error C5060: out can't be used with non-varying color

(I have tested this on latest opengl version but I assume opengl2 should be backwards compatible)

It looks like we shouldn't even use shader at all for GL2

I've also tried the latest version from 'ImplGL2' branch (with libgdx 1.9.8 though) and got this stacktrace:

java.lang.Exception: ERROR: 0:7: Invalid storage qualifiers 'in' in global variable context
ERROR: 0:8: Invalid storage qualifiers 'in' in global variable context
ERROR: 0:9: Invalid storage qualifiers 'in' in global variable context
ERROR: 0:11: Invalid storage qualifiers 'out' in global variable context
ERROR: 0:12: Invalid storage qualifiers 'out' in global variable context
ERROR: 0:16: Use of undeclared identifier 'uv'
ERROR: 0:16: Use of undeclared identifier 'UV'
ERROR: 0:17: Use of undeclared identifier 'color'
ERROR: 0:17: Use of undeclared identifier 'Color'
ERROR: 0:18: Use of undeclared identifier 'Position'
�
	at gln.objects.GlShader$Companion.createFromSource-RHQEpZs(shader.kt:70)
	at imgui.impl.ImplGL2.createDeviceObjects(ImplGL2.kt:49)
	at imgui.impl.LwjglGlfw.newFrame(LwjglGlfw.kt:154)
	at imgui.impl.LwjglGlfw$Companion.newFrame(LwjglGlfw.kt:34)

Should be fixed in ImplGL2 commit 4b38958

Ok now It works but there is still some issue when I resize window, does not happen on opengl3
image

        context = Context()

        val openGLVersion = if (Gdx.graphics.glVersion.majorVersion < 3) {
            LwjglGlfw.GlfwClientApi.OpenGL2
        } else {
            LwjglGlfw.GlfwClientApi.OpenGL
        }
        LwjglGlfw.init(GlfwWindow.from((Gdx.graphics as Lwjgl3Graphics).window.windowHandle), clientApi_ = openGLVersion)
        ImGui.io.iniFilename = null
        ImGui.styleColorsDark()
    override fun renderScene(delta: Float) {
        LwjglGlfw.newFrame()
        ImGui.newFrame()

       ...

        ImGui.render()
        ImGui.drawData?.run {
            LwjglGlfw.instance.renderDrawData(this)
        }
    }

I cannot reproduce this issue. Is there something specific I need to do?

ps: ImGui.drawData?.run(LwjglGlfw.instance::renderDrawData)

@Sylvyrfysh Try test lwjgl.kt and change to GlfwClientApi.OpenGL2 I am testing this on latest opengl version right now but this should be not a problem?

looks something wrong with the clearing, maybe it has something to do with the scissor?

Retina mac?

Right now I can not test it on Mac hardware. Currently I am using linux mint.

Was able to reproduce after changing the window size. Looking into it

Yes happens only when you resize the window :)

That one works correctly! 👍 I will try It on mac and let you know how It works there.

Ok It also works on Mac. Thanks for your help! I appreciate It 👍

No problem!

org.lwjgl.opengl.GL11C.nglDrawElements(IIIJ)V (0 bytes) @ 0x00000001155416c4 [0x0000000115541600+0xc4]
J 1294 C1 com.badlogic.gdx.backends.lwjgl3.Lwjgl3GL20.glDrawElements(IIILjava/nio/Buffer;)V (124 bytes) @ 0x0000000115538e94 [0x0000000115537880+0x1614]
J 1273 C1 com.badlogic.gdx.graphics.Mesh.render(Lcom/badlogic/gdx/graphics/glutils/ShaderProgram;IIIZ)V (257 bytes) @ 0x000000011552707c [0x00000001155269e0+0x69c]
J 1243 C1 com.badlogic.gdx.graphics.g2d.SpriteBatch.flush()V (193 bytes) @ 0x00000001155165ec [0x00000001155159c0+0xc2c]
J 2121 C1 com.badlogic.gdx.graphics.g2d.SpriteBatch.end()V (90 bytes) @ 0x000000011598a034 [0x0000000115989f20+0x114]
J 2592 C1 com.x.prototype.screen.editor.TileEditorScreen.renderScene(F)V (607 bytes) @ 0x0000000115e2578c [0x0000000115e1fe40+0x594c]
J 2715 C1 com.x.prototype.screen.base.BaseScreen.render(F)V (33 bytes) @ 0x0000000115fe137c [0x0000000115fe0c60+0x71c]
J 2711 C1 com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update()Z (213 bytes) @ 0x0000000115fdd1d4 [0x0000000115fdbfa0+0x1234]
j  com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop()V+101
j  com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lcom/badlogic/gdx/ApplicationListener;Lcom/badlogic/gdx/backends/lwjgl3/Lwjgl3ApplicationConfiguration;)V+257

This error happens only on opengl2 when I try to render something libgdx related in my render method:

LwjglGlfw.newFrame()
ImGui.newFrame()
.....
ImGui.render()
ImGui.drawData?.run(LwjglGlfw.instance::renderDrawData)

app.batch.begin()
app.batch.draw(app.assetManager.get<Texture>(path), 0f, 0f , 10f, 10f)
app.batch.end()

I have added

Does your machine support opengl 4.3?

I am testing this on OpenGL 4.6 and switched Imgui to OpenGL2 version but also happens on mac with open gl 2.1

After your init, plug this code in:

    glEnable(GL43.GL_DEBUG_OUTPUT)
    glEnable(GL43.GL_DEBUG_OUTPUT_SYNCHRONOUS)

    cb = GLDebugCallback_43()
    glDebugMessageCallback(cb, 1)
    glDebugMessageControl(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, BufferUtils.createIntBuffer(0),
            true)`

and add this class somewhere

class GLDebugCallback_43 : GLDebugMessageCallback() {

override fun invoke(source: Int, type: Int, id: Int, severity: Int, len: Int, msg: Long, udata: Long) {
    if (id == 131185 || id == 131218)
    // || id == 131186
        return
    val _source: String = when (source) {
        GL_DEBUG_SOURCE_API -> "API"

        GL_DEBUG_SOURCE_WINDOW_SYSTEM -> "WINDOW SYSTEM"

        GL_DEBUG_SOURCE_SHADER_COMPILER -> "SHADER COMPILER"

        GL_DEBUG_SOURCE_THIRD_PARTY -> "THIRD PARTY"

        GL_DEBUG_SOURCE_APPLICATION -> "APPLICATION"

        GL_DEBUG_SOURCE_OTHER -> "UNKNOWN"
        else -> "UNKNOWN"
    }
    val _type: String
    val _severity: String = when (severity) {
        GL_DEBUG_SEVERITY_HIGH -> "HIGH"

        GL_DEBUG_SEVERITY_MEDIUM -> "MEDIUM"

        GL_DEBUG_SEVERITY_LOW -> "LOW"

        GL_DEBUG_SEVERITY_NOTIFICATION -> "NOTIFICATION"

        else -> "UNKNOWN"
    }

    when (type) {
        GL_DEBUG_TYPE_ERROR -> _type = "ERROR"

        GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR -> _type = "DEPRECATED BEHAVIOR"

        GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR -> _type = "UNDEFINED BEHAVIOR"

        GL_DEBUG_TYPE_PORTABILITY -> _type = "PORTABILITY"

        GL_DEBUG_TYPE_PERFORMANCE -> _type = "PERFORMANCE"

        GL_DEBUG_TYPE_OTHER -> _type = "OTHER"

        GL_DEBUG_TYPE_MARKER -> _type = "MARKER"

        else -> _type = "UNKNOWN"
    }

    println("ID $id: $_type of $_severity severity, raised from $_source: ${MemoryUtil.memASCII(msg)}")
    println("STACKTRACE:")
    Thread.currentThread().stackTrace.forEach(::println)
}
}`

share what happens back her and i'll se if it's something we're doing

From that stacktrace, ImGui is not doing anything to cause that. Did nothing get printed to console?

new buffers sizes, vtx: 2048, idx: 1024
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000041023e67, pid=3816, tid=0x00007f7e015a6700
#
...

See if 48c582f fixes it

It didn't help :-/

If you comment out imgui calls, does it work fine?

If I comment out everything from LwjglGlfw.newFrame(), ImGui.newFrame() to LwjglGlfw.instance.renderDrawData (and keep LwjglGlfw.init, context and all initialization) and draw something on screen using libgdx batch It works.

What about only commenting out only renderDrawData?

Same issue. And keep in mind this problem happens only with OpenGL2. On opengl3 It works without problems.

I guess then the only way to find out is to comment out internally everything of createDeviceObjects, then uncomment step by step to find out the problematic call

guitest.zip

I can easily simulate It with this demo. For me same issue - opengl3+ works correctly and opengl2 crashes

btw, thanks for your donation, appreciated!

Tada! 2c1f58f

On a side note, I'll talk to the LibGDX guys about fixing stuff like that on their end too. Thanks for working with us through this

Good this one works correctly! 👍

hs_err_pid19901.log
There is still one issue but this one will be probably harder. It does happen on Mac only with OpenGL2. It doesn't happen for me on Linux (when testing OpenGL2). It happens randomly or with some interaction in UI (and libgdx combination).

This is a JVM bug specifically affecting Mac. Find it here

Hm 🤔 but this does not happen on other screens where we do not use ImGui.

That's due to the compilation failing on getDrawData. I'll see if I can modify the code to fix it, but it's doubtful

May trying another jdk be an option for you, @yuraj11? Like jdk11?

But I second elect's trying a different JDK

Sorry I can not test It right now but I will check It tomorrow. I can also try with latest JDK after testing your change.

guitest.zip
Something happened and I tried reverting your last change in ImplGL2 branch but does not help. I see you have rebased changes from master which probably contained some change which broke opengl2. You can check demo. It cointains latest implgl2 branch library. Somehow UI will dimiss after libgdx is drawing something. Didn't happen previously and there is no problem on opengl3.

It is caused by this change 5b5112c

Beside the mentioned issue It looks that d2c5266 fixes the SIGSEGV crash on Mac (will report If something changes).

That is the change that fixes the memory leak. Try the latest changes, fixed again with a new memory eak workaround

Now everything works good now.

No issues with OpenGL2 on Mac so far 👍

hs_err_pid5129.log
One more random crash on Mac (OpenGL2). Happens rarely comparing to previous issues. Happens when changing screens.

Weird, that belongs to stb though, so it should be outside our reaching area

An update to stb is coming to lwjgl though

Ignore that last issue. It is probably on our side 🤦‍♂️ (I am calling multiple times LwjglGlfw.init, ImGui.addFont etc. in onShow method which is called when you come back from other screen but dispose is not called so that's why It happens only when you return from other screen) Anyway I think you can merge opengl2 branch to master. It is stable now.

And thanks for your help again!

Nice, ok then I'll merge later

Thank you, dear

hs_err_pid2411.log
hs_err_pid2428.log
I have found two random issues on Mac OpenGL2 :-/ The previous looks like fixed but this one happens on first time when opening the screen.