kotlinlibgdxskinlibktx

libgdx holo-skin: no No SelectBoxStyle registered with name: default


I am trying to find my way into LibGDX, using the libKtx extensions, and trying to get my first piece of UI going. I wanted to add a SelectBox to set the window resolution, but I'm getting an exception when setting the stage:

Exception in thread "main" com.badlogic.gdx.utils.GdxRuntimeException: No com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle registered with name: default
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.get(Skin.java:162)
    at com.badlogic.gdx.scenes.scene2d.ui.SelectBox.<init>(SelectBox.java:80)
    at ktx.scene2d.KSelectBox.<init>(widget.kt:405)
    at ch.raoc.sublighttrader.screen.ConfigMenu.setStage(ConfigMenu.kt:132)
    at ch.raoc.sublighttrader.screen.ConfigMenu.<init>(ConfigMenu.kt:16)
    at ch.raoc.sublighttrader.Main.create(Main.kt:37)

I'm using the Holo-dark skin from here for testing, and I had a look at the json file and verified that there should indeed be a "default" style for SelectBox in there:

    com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle: {
        default: { background: spinner_default, backgroundOver: spinner_focused, backgroundOpen: spinner_pressed, listStyle: default, scrollStyle: opaque, font: default-font, fontColor: text-dark },
        default-thin: { background: spinner_default, backgroundOver: spinner_focused, backgroundOpen: spinner_pressed, listStyle: default-thin, scrollStyle: opaque, font: thin-font, fontColor: text-dark }
    },

Loading of the skin looks like this, and as mentioned, other elements I've tried are working fine, so I don't think this is an issue: Skin(Gdx.files.internal("${assetPath}ui/skin/dark-mdpi/Holo-dark-mdpi.json"))

The particular menu definition where this happens looks like this:

    private fun setStage() {
        stage.actors {
            table {
                setFillParent(true)
                left()
                top()
                textButton("Back", skin = manager.skin) {
                    onChange {
                        // TODO: Breadcrumbs!
                        manager.showMainMenu()
                    }
                }
            }
            table {
                defaults().fillX().uniformX()
                setFillParent(true)


                label("Options", skin = manager.skin) {
                    setAlignment(Align.center)
                }
                row()
                selectBox<String> {
                    setItems(
                        "1920x1080",
                        "1792x1008",
                        "1664x936",
                        "1536x864",
                        "1408x792",
                        "1280x720",
                        "1152x648",
                        "1024x576"
                    )
                }
            }
        }
    }

If I comment out the selectBox, everything works fine.

Essentially I have two questions: What might be wrong with that json? (well, if it were actual json I'd see a lot wrong with it, but it seems that the libGDX parser doesn't bother much with quotation, otherwise nothing in here would work. And at least the buttons and labels are working just fine)

And the other question, can I get libGDX to log the skin parsing somehow? Then I might be able to troubleshoot such issues on my own, but right now all I have is a perfectly fine (seeming) skin that I didn't write myself and an exception that for all I can tell shouldn't be there, without any information on how the two fit together.

Addendum

I'm really running out of ideas here. I tried a different skin, thinking maybe that one had an issue just nobody ever noticed. But other skins are throwing the same error when attempting to instantiate a SelectBox. I thought maybe something somewhere was not compatible with the version I'm using, but I've checked all the fields of the style classes and compared them to the json, and they all match, all fields that cannot be null are initialised. So are ListStyle and ScrollPaneStyle, the two styles that SelectBox has a dependency on. Everything seemed fine there as well.

I took a close look at the skin in the debugger, as far as I can see there's a default style for SelectBox, as well as for the two depending styles:

skin in debugger

And yet, libGDX keeps telling me that there is no default style for SelectBox, without any further info. I don't know where to continue...


Solution

  • Found the problem between chair and keyboard.

    I'm not passing the bloody skin to the factory, and I didn't notice from looking way too hard in all the wrong places. So this:

    selectBox<String> {
                        ...
                    }
    

    quite obviously has to be this:

    selectBox<String>(skin = manager.skin) {
                        ...
                    }