utopia-rise / godot-kotlin-jvm

Godot Kotlin JVM Module
MIT License
636 stars 44 forks source link

Enum properties generation bug #489

Closed chippmann closed 1 year ago

chippmann commented 1 year ago

Enum property setters in the api are wrongly generated. They try to put themselves into the transfer context rather their enclosing ordinal (id):

  public var mouseFilter: MouseFilter
    get() {
      TransferContext.writeArguments()
      TransferContext.callMethod(rawPtr, ENGINEMETHOD_ENGINECLASS_CONTROL_GET_MOUSE_FILTER, LONG)
      return Control.MouseFilter.values()[(TransferContext.readReturnValue(LONG) as Long).toInt()]
    }
    set(`value`) {
      TransferContext.writeArguments(LONG to value) // <- bug here. should be `value.id`
      TransferContext.callMethod(rawPtr, ENGINEMETHOD_ENGINECLASS_CONTROL_SET_MOUSE_FILTER, NIL)
    }

This leads to:

Exception in thread "main" java.lang.IllegalArgumentException: Failed requirement.
        at godot.core.VariantType$6.invoke(Variant.kt:190)
        at godot.core.VariantType$6.invoke(Variant.kt:189)
        at godot.core.VariantType$toGodot$1.invoke(Variant.kt:760)
        at godot.core.VariantType$toGodot$1.invoke(Variant.kt:756)
        at godot.core.memory.TransferContext.writeArguments(TransferContext.kt:36)
        at godot.Control.setMouseFilter(Control.kt:489)
        at ch.hippmann.pncframework.node.singleton.DragAndDropManager$dragDataNode$2.invoke(DragAndDropManager.kt:31)
        at ch.hippmann.pncframework.node.singleton.DragAndDropManager$dragDataNode$2.invoke(DragAndDropManager.kt:28)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at ch.hippmann.pncframework.node.singleton.DragAndDropManager.getDragDataNode(DragAndDropManager.kt:28)
        at ch.hippmann.pncframework.node.singleton.DragAndDropManager._ready(DragAndDropManager.kt:102)
        at godot.entry.DragAndDropManagerRegistrar$register$1$1$6.invoke(DragAndDropManagerRegistrar.kt:42)
        at godot.entry.DragAndDropManagerRegistrar$register$1$1$6.invoke(DragAndDropManagerRegistrar.kt:42)
        at godot.core.KtFunction0.invokeKt$godot_library(Functions.kt:80)
        at godot.core.callable.KtCallable.invoke(KtCallable.kt:21)

The failing requirement:

    LONG(
        2,
        { buffer: ByteBuffer, _: Int ->
            buffer.long
        },
        { buffer: ByteBuffer, any: Any ->
            require(any is Long) // <- fails here as `any` is not of type `Long` but of type `Enum`
            buffer.variantType = LONG.ordinal
            buffer.putLong(any)
        }
    ),