Skip to content

popupContextWindow in listBox #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yuraj11 opened this issue May 10, 2019 · 40 comments
Closed

popupContextWindow in listBox #88

yuraj11 opened this issue May 10, 2019 · 40 comments

Comments

@yuraj11
Copy link

yuraj11 commented May 10, 2019

This has been working previously but now It freezes entire application with latest changes:

listBoxHeader()
popupContextWindow {
...
}
listBoxFooter()
@elect86
Copy link
Collaborator

elect86 commented May 10, 2019

I cant reproduce, can you specify it further?

@yuraj11
Copy link
Author

yuraj11 commented May 10, 2019

listBoxHeader("Test")
selectable("ABC")
popupContextWindow {
    menuItem("Test")
}
listBoxFooter()

and then It freezes after right click on listbox

elect86 added a commit that referenced this issue May 11, 2019
@elect86
Copy link
Collaborator

elect86 commented May 11, 2019

I fixed this in the test2 branch

Also, this feature a reworked backends (closer to cpp).. may you give it a try?

I have no way to test against gl profiles lower than 3.0

@yuraj11
Copy link
Author

yuraj11 commented May 12, 2019

I have tried commit 78ede0a It works there but I see previous issues again - no text in context menus.

@elect86
Copy link
Collaborator

elect86 commented May 12, 2019

pull the master, I merged it back.

The big change there is a general rework on the backend in order to narrow the gap with the cpp. I took the chance of an original commit modifying those to do that.

Also, the text in the context menus is also fixed, we shall pass -1 as Null when it comes to Strings. I'll add this to the readme

Also2: could you test the gl2 samples? It runs fine on me, but of course it picks 4.5, which is the highest profile on mine.. (I cant specify it since there profiles doesnt exist prior 3.0)

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

I have pulled latest master changes. It works to certain degree. When I am interacting with scrollable panels It freezes entire application. I am testing in on opengl 3+. You can simulate this bug in imgui demo application (demo section SimpleLayout - Scrolling). Same problem with drag & drop feature.

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

I use imgui for only one screen in my application. When I close the screen I call destroy as noted below. But when I recreate this screen (call init { } again) I see only black screen. Not sure If something has changed or am I doing something wrong (Previously I did not have this problem).

This is how I use imgui with libgdx:

    init {
        val window = GlfwWindow.from((Gdx.graphics as Lwjgl3Graphics).window.windowHandle)
        context = Context()

        imguiInputProcessor = ImGuiInputProcessor(window)
        glInterface = if (Gdx.graphics.glVersion.majorVersion < 3) ImplGL2() else ImplGL3()
        implGlfw = ImplGlfw(window)

        ImGui.io.iniFilename = null
        ImGui.styleColorsDark()
        ImGui.addFont("font/roboto.ttf", 18f)
        windows.welcomeWindow.visible = true

        //Register shortcuts
        initShortcuts()

        //Default input processor
        setInputProcessors(imguiInputProcessor)
    }

Render method:

loop() {
... libgdx render calls

glInterface.newFrame()
implGlfw.newFrame()
ImGui.newFrame()

... imgui render calls

ImGui.render()
ImGui.drawData?.run(glInterface::renderDrawData)
}

and destroy method called when user exits this screen:

glInterface.shutdown()
implGlfw.shutdown()
context.destroy()

And here is input processor (modified for latest changes in master):

class ImGuiInputProcessor(private val window: GlfwWindow) : InputAdapter() {
    private val gdxGLFWKeyMap = mutableMapOf<Int, Int>()

    init {
        gdxGLFWKeyMap[Input.Keys.TAB] = GLFW.GLFW_KEY_TAB

        gdxGLFWKeyMap[Input.Keys.LEFT] = GLFW.GLFW_KEY_LEFT
        gdxGLFWKeyMap[Input.Keys.RIGHT] = GLFW.GLFW_KEY_RIGHT
        gdxGLFWKeyMap[Input.Keys.UP] = GLFW.GLFW_KEY_UP
        gdxGLFWKeyMap[Input.Keys.DOWN] = GLFW.GLFW_KEY_DOWN

        gdxGLFWKeyMap[Input.Keys.PAGE_UP] = GLFW.GLFW_KEY_PAGE_UP
        gdxGLFWKeyMap[Input.Keys.PAGE_DOWN] = GLFW.GLFW_KEY_PAGE_DOWN

        gdxGLFWKeyMap[Input.Keys.HOME] = GLFW.GLFW_KEY_HOME
        gdxGLFWKeyMap[Input.Keys.END] = GLFW.GLFW_KEY_END

        gdxGLFWKeyMap[Input.Keys.BACKSPACE] = GLFW.GLFW_KEY_BACKSPACE

        gdxGLFWKeyMap[Input.Keys.ENTER] = GLFW.GLFW_KEY_ENTER
        gdxGLFWKeyMap[Input.Keys.ESCAPE] = GLFW.GLFW_KEY_ESCAPE

        gdxGLFWKeyMap[Input.Keys.CONTROL_LEFT] = GLFW.GLFW_KEY_LEFT_CONTROL
        gdxGLFWKeyMap[Input.Keys.CONTROL_RIGHT] = GLFW.GLFW_KEY_RIGHT_CONTROL
        gdxGLFWKeyMap[Input.Keys.ALT_LEFT] = GLFW.GLFW_KEY_LEFT_ALT
        gdxGLFWKeyMap[Input.Keys.ALT_RIGHT] = GLFW.GLFW_KEY_RIGHT_ALT
        gdxGLFWKeyMap[Input.Keys.SHIFT_LEFT] = GLFW.GLFW_KEY_LEFT_SHIFT
        gdxGLFWKeyMap[Input.Keys.SHIFT_RIGHT] = GLFW.GLFW_KEY_RIGHT_SHIFT

        gdxGLFWKeyMap[Input.Keys.A] = GLFW.GLFW_KEY_A
        gdxGLFWKeyMap[Input.Keys.C] = GLFW.GLFW_KEY_C
        gdxGLFWKeyMap[Input.Keys.V] = GLFW.GLFW_KEY_V
        gdxGLFWKeyMap[Input.Keys.X] = GLFW.GLFW_KEY_X
        gdxGLFWKeyMap[Input.Keys.Y] = GLFW.GLFW_KEY_Y
        gdxGLFWKeyMap[Input.Keys.Z] = GLFW.GLFW_KEY_Z
    }

    override fun keyTyped(character: Char): Boolean {
        window.charCallback?.invoke(character.toInt())
        return false
    }

    override fun scrolled(amount: Int): Boolean {
        window.scrollCallback?.invoke(Vec2d(0, -amount))
        return false
    }

    override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
        window.mouseButtonCallback?.invoke(button, GLFW.GLFW_PRESS, 0)
        return false
    }

    override fun keyUp(keycode: Int): Boolean {
        gdxGLFWKeyMap[keycode]?.apply {
            window.keyCallback?.invoke(this, 0, GLFW.GLFW_RELEASE, 0)
        }
        return false
    }

    override fun keyDown(keycode: Int): Boolean {
        gdxGLFWKeyMap[keycode]?.apply {
            window.keyCallback?.invoke(this, 0, GLFW.GLFW_PRESS, 0)
        }
        return false
    }
}

elect86 added a commit that referenced this issue May 13, 2019
@elect86
Copy link
Collaborator

elect86 commented May 13, 2019

Ok, freeze shall be solved by now. Scrollbar has been quite intensively reworked by Omar though

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

Ok freeze is gone. I have added checkError in mainloop end and when I see black screen (when imgui is created) I am getting this error:

Caused by: java.lang.Exception: OpenGL Error (GL_INVALID_VALUE) at mainLoop
	at gln.GlnKt.checkError(gln.kt:79)
	at gln.GlnKt.checkError$default(gln.kt:62)

@elect86
Copy link
Collaborator

elect86 commented May 13, 2019

Are you re-instantiating both glfw and gl impl?

    implGlfw = ImplGlfw(window, true)
    implGl3 = ImplGL3()

it could make sense to extract the constructor initialization and make it exactly as cpp ImGui_ImplGlfw_Init()..

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

Yes as mentioned above:

val window = GlfwWindow.from((Gdx.graphics as Lwjgl3Graphics).window.windowHandle)
context = Context()
glInterface = if (Gdx.graphics.glVersion.majorVersion < 3) ImplGL2() else ImplGL3()
implGlfw = ImplGlfw(window)

I am reusing existing libgdx window.

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

I could create libgdx+imgui demo to reproduce this issue If you want.

@elect86
Copy link
Collaborator

elect86 commented May 13, 2019

I think we may do something like this for the long term, in order to have a real test scenario to test/debug against (I'm also keeping an eye on this)

But for the moment I managed to get the same exception with a simple

fun main() {
    ImGuiOpenGL3()
    ImGuiOpenGL3()
}

elect86 added a commit that referenced this issue May 13, 2019
@elect86
Copy link
Collaborator

elect86 commented May 13, 2019

Try again please

Also, do not call glfw.terminate() if you want to re-use imgui again because it'll dispose the native callbacks which wont be re-instantiate at the next start. Use GLFW.glfwTerminate() in the meanwhile

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

I think I don't need to call glfw terminate in both ways because I don't want to close my window. Anyway with latest changes It works correctly now. Will let you know how It will work on mac and opengl 2.

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

GL2 & GL3 works on Linux = ✔️
GL2 on Mac = ❌ - black screen and I don't see any opengl error

@elect86
Copy link
Collaborator

elect86 commented May 13, 2019

Could you give a try to the native imgui regarding GL2 on Mac?

@yuraj11
Copy link
Author

yuraj11 commented May 13, 2019

#79 (comment)
is not that similar issue you have fixed before?
BTW I read that Apple is pushing developers to use Metal instead of OpenGL which is deprecated on Mac.

@elect86
Copy link
Collaborator

elect86 commented May 13, 2019

Unfortunately that cant be culprit in the case..

I created a parallel test in order to debug (you can find it here), are you available to go together step by step?

@elect86
Copy link
Collaborator

elect86 commented May 14, 2019

Ok, let's see if you can first see the screen cleared with the default color background, run the sample and report :)

@yuraj11
Copy link
Author

yuraj11 commented May 14, 2019

Crashes on mac:

Forward-compatibility is only defined for OpenGL version 3.0 and above
Exception in thread “main” java.lang.RuntimeException: Failed to create the GLFW window
    at uno.glfw.GlfwWindow.<init>(GlfwWindow.kt:85)
    at uno.glfw.GlfwWindow.<init>(GlfwWindow.kt:48)
    at uno.glfw.GlfwWindow.<init>(GlfwWindow.kt:70)
    at uno.glfw.GlfwWindow.<init>(GlfwWindow.kt:69)
    at imgui.ImGuiOpenGL2_Mac.<init>(opengl2_mac.kt:52)
    at imgui.Opengl2_macKt.main(opengl2_mac.kt:23)
    at imgui.Opengl2_macKt.main(opengl2_mac.kt)

elect86 added a commit that referenced this issue May 14, 2019
@elect86
Copy link
Collaborator

elect86 commented May 14, 2019

Right, skipped, 2c6b3d6

@yuraj11
Copy link
Author

yuraj11 commented May 14, 2019

crash

2019-05-14 19:40:06.170 java[34647:1585339] WARNING: nextEventMatchingMask should only be called from the Main Thread! This will throw an exception in the future.
2019-05-14 19:40:06.171 java[34647:1585339] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1562/Foundation/Misc.subproj/NSUndoManager.m:361
2019-05-14 19:40:06.171 java[34647:1585339] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1562/Foundation/Misc.subproj/NSUndoManager.m:361
2019-05-14 19:40:06.173 java[34647:1585339] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.’
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff3c8cdded __exceptionPreprocess + 256
    1   libobjc.A.dylib                     0x00007fff68995720 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff3c8e8a4a +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x00007fff3ec8ce0d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
    4   Foundation                          0x00007fff3ebbd249 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 469
    5   AppKit                              0x00007fff39d6024e -[NSApplication run] + 932
    6   libglfw.dylib                       0x000000012b7169d5 libglfw.dylib + 68053
    7   libglfw.dylib                       0x000000012b710366 libglfw.dylib + 41830
    8   ???                                 0x0000000105da4667 0x0 + 4393158247
    9   ???                                 0x0000000105d93dd0 0x0 + 4393090512
    10  ???                                 0x0000000105d93dd0 0x0 + 4393090512
    11  ???                                 0x0000000105d93dd0 0x0 + 4393090512
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@elect86
Copy link
Collaborator

elect86 commented May 14, 2019

do you have something more?

the main thread warning is suspicious, is the application doing fancy things with threads?

@elect86
Copy link
Collaborator

elect86 commented May 15, 2019

sorry, my bad, ImGuiOpenGL2_Mac was still using the wrong backend, try again please, 64fa3fa

@yuraj11
Copy link
Author

yuraj11 commented May 15, 2019

That thread issue was solved by -XstartOnFirstThread (which we also use with libgdx lwjgl - It's required on mac). And with latest changes It works now and I see greenish background.

@yuraj11
Copy link
Author

yuraj11 commented May 15, 2019

I think there is problem with imgui and libgdx compatibility (on mac).

@elect86
Copy link
Collaborator

elect86 commented May 15, 2019

fe2c00a, do you see the square?

elect86 added a commit that referenced this issue May 15, 2019
@elect86
Copy link
Collaborator

elect86 commented May 15, 2019

forgot to push

@yuraj11
Copy link
Author

yuraj11 commented May 15, 2019

Yes there is a square.

@yuraj11
Copy link
Author

yuraj11 commented May 28, 2019

Do you have any idea what could be the problem?

@elect86
Copy link
Collaborator

elect86 commented May 29, 2019

sorry, but I was working on re-structuring the project implementing a multi-module structure

Now, you should have the opengl2_mac under the imgui-gl module..

Confirm me everything is working as previously and the square is still there and we move forward

@yuraj11
Copy link
Author

yuraj11 commented May 30, 2019

It works correctly as previously.

elect86 added a commit that referenced this issue May 31, 2019
@elect86
Copy link
Collaborator

elect86 commented May 31, 2019

ok, now try 21223fd

@yuraj11
Copy link
Author

yuraj11 commented May 31, 2019

Yes It works.

elect86 added a commit that referenced this issue Jun 1, 2019
@elect86
Copy link
Collaborator

elect86 commented Jun 1, 2019

97d8a7d ?

@yuraj11
Copy link
Author

yuraj11 commented Jun 3, 2019

It works.

@yuraj11
Copy link
Author

yuraj11 commented Jun 5, 2019

You could try adding libgdx and combining It with imgui.

elect86 added a commit that referenced this issue Jun 12, 2019
@elect86
Copy link
Collaborator

elect86 commented Jun 12, 2019

The problem is that you cant explicitely ask for gl contexts lower than 3.2

And I dont have a machine to test

5409397?

@yuraj11
Copy link
Author

yuraj11 commented Jun 24, 2019

We can close this issue as the problem was solved and macos compatibility related stuff will be in #79

@yuraj11 yuraj11 closed this as completed Jun 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants