Alternatively, if someone could explain what's wro...
# kotlin-native
m
Alternatively, if someone could explain what's wrong:
Copy code
kotlin
abstract class Node {
    abstract fun process()
    abstract fun cleanup()
    abstract val inputs: Map<String, CArrayPointer<FloatVar>>
    abstract val outputs: List<String>

    fun connect(output: String, receivingNode: Node, input: String) {
        if (!outputs.contains(output)) {
            throw IllegalArgumentException("Unknown node output name! (Connecting ${this::class.simpleName}.$output to ${receivingNode::class.simpleName}.$input)")
        }
        val new = mutableMapOf<String, CArrayPointer<FloatVar>>().also {
            it.putAll(this.connections.value)
            it[output] = receivingNode.getInputBuffer(input)
        }
        this.connections.value = new
    }

    fun getOutputBuffer(name: String) : CArrayPointer<FloatVar>? = connections.value[name]

    /* internals below */

    private val connections = AtomicReference(mapOf<String, CArrayPointer<FloatVar>>())
    private fun getInputBuffer(name: String) : CArrayPointer<FloatVar> = inputs[name] ?: throw IllegalArgumentException("Unknown node input name! (${this::class.simpleName}.$name)");
}
For some reason somewhere in
connect
, it throws an error because a map that is supposedly already frozen gets modified, but I don't see where that happens.
k
Exception?