Skip to content
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

StackOverflow on basic sound playback #2265

Open
chris-hatton opened this issue Jul 6, 2024 · 0 comments
Open

StackOverflow on basic sound playback #2265

chris-hatton opened this issue Jul 6, 2024 · 0 comments

Comments

@chris-hatton
Copy link

chris-hatton commented Jul 6, 2024

When using either artifact...

"com.soywiz.korge:korge-core:5.1.0"

...or...

"com.soywiz.korge:korge-core:6.0.0-alpha9"

...what appears to be a basic Audio Playback usage fails on both JVM and JS (so likely in common code) with the following:

ℹ️ The sound actually does play - the crash seems to occur at completion

JVM Error

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
	at korlibs.audio.sound.SoundKt.getPlaying(Sound.kt:307)
	at korlibs.audio.sound.SoundAudioData$play$2.getState(SoundAudioStream.kt:69)
	at korlibs.audio.sound.SoundKt.getPlaying(Sound.kt:307)
	at korlibs.audio.sound.SoundAudioData$play$2.getState(SoundAudioStream.kt:69)

JS Error

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at <org.chrishatton:homepage>.korlibs.audio.sound.<no name provided>.<get-state> (http://localhost:8080/homepage.wasm:wasm-function[66319]:0xb560ce)
    at <org.chrishatton:homepage>.korlibs.audio.sound.<get-playing> (http://localhost:8080/homepage.wasm:wasm-function[66265]:0xb550e3)
    at <org.chrishatton:homepage>.korlibs.audio.sound.<no name provided>.<get-state> (http://localhost:8080/homepage.wasm:wasm-function[66319]:0xb560f4)
    at <org.chrishatton:homepage>.korlibs.audio.sound.<get-playing> (http://localhost:8080/homepage.wasm:wasm-function[66265]:0xb550e3)
    at <org.chrishatton:homepage>.korlibs.audio.sound.<no name provided>.<get-state> (http://localhost:8080/homepage.wasm:wasm-function[66319]:0xb560f4)
    at <org.chrishatton:homepage>.korlibs.audio.sound.<get-playing> (http://localhost:8080/homepage.wasm:wasm-function[66265]:0xb550e3)

Slightly condensed reproduction example (for usage context)

This example shows how I'm trying to use Korge with Jetpack Compose, though the actual Korge/KorAu API touch-points are probably the only significant thing:

@OptIn(ExperimentalResourceApi::class)
@Composable
fun AudioCrashExample() {

    var sound: Sound? by remember { mutableStateOf(null) } // <-- Load sound
    val scope = rememberCoroutineScope()

    // This coroutine loads the sound (appears to work in debug)
    LaunchedEffect(null) {
        val soundBytes = Res.readBytes("files/button.wav")
        val audioData = WAV.decode(data = soundBytes)!!
        sound = nativeSoundProvider.createNonStreamingSound(audioData, "button")
    }
    Button(
        onClick = {
            scope.launch { sound?.play()?.await() } // <-- Trigger sound, this causes the crash
        },
    ) {
        Text("Play sound")
    }
}

Further condensed example

Cutting out the Jetpack Compose code; this is how I'm driving Korge:

val soundBytes = Res.readBytes("files/button.wav")
val audioData = WAV.decode(data = soundBytes)!!
val sound = nativeSoundProvider.createNonStreamingSound(audioData, "button")
sound.play().await()

...this seems to be a simple example. I'm new to KorGE but a quick inspection of the JVM stack trace does make it look like a straightforward bug in its playback state management(?). Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Pending
Development

Successfully merging a pull request may close this issue.

1 participant