I have downloaded the basic KorGE demo scene, and ...
# korge
c
I have downloaded the basic KorGE demo scene, and ran into an issue: if I create more than two images and added a filter to each of them, the app crashes almost immediately on mobile. Doesn't matter the filter (whether it's a blur, an Identity Filter, whatever) or the size of the image. On JVM, it seems to be working properly and smoothly, but running on mobile it simply crashes. The error I'm getting is
Copy code
Fatal signal 11 (SIGSEGV) at 0x42a637d9 (code=1)
Seems like some sort of concurrency issue. Having a class that runs glFinish() on every render pass mitigates the problem to a certain point (up to 8 to 10 images), but even with small amount of images and running a very simple filter, the FPS drops to about 8 or 9.
d
Can you share the code? It is an emulator or a real device? By mobile means android or ios (they are pretty different versions)? Which operating system/version? In general all the info you can provide to reproduce the problem on our side will be appreciated
m
I’m facing a similar issue when trying to run filters sample in korge-next repo. It crashes on JVM and native but works fine on JS • Device: MacBook Pro (16-inch, 2019) • OS: macOS Big Sur version 11.5.2 • Java: openjdk version 11.0.11 Attaching stacktraces for Java and native
d
Oh fu. Ill check. Are you running it in korge-samples? Or enabling the samples in korge-next by modifying the settings.gradle?
👍 1
c
I'm running it on a Xiaomi Mi 9T, Android 10 QKQ1.190825.002, haven't tried it on iOS.
m
The later one, by enabling it on korge-next
c
this is my code running the commonTest/kotlin/main.kt:
Copy code
import com.soywiz.klock.*
import com.soywiz.korge.*
import com.soywiz.korge.tween.*
import com.soywiz.korge.view.*
import com.soywiz.korge.view.filter.BlurFilter
import com.soywiz.korge.view.filter.IdentityFilter
import com.soywiz.korim.color.*
import com.soywiz.korim.format.*
import com.soywiz.korio.file.std.*
import com.soywiz.korma.geom.*
import com.soywiz.korma.interpolation.*

suspend fun main() = Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"]) {

   var iter = 0
   repeat(3, {
      val image = image(resourcesVfs["korge.png"].readBitmap()) {
         rotation = 0.degrees
         anchor(.5, .5)
         scale(0.1)
         position(256, 30 * iter)
      }
   })

// while (true) {
//    image.tween(image::rotation[minDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT)
//    image.tween(image::rotation[maxDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT)
// }
}
oh, and it's a real device, not emulator
d
Thanks for the context Mayank and Carl! Sure it helps. I will try to reproduce it myself
🙏 1
👍 1
s
@Deactivated User any clues on this one?
d
I have annotated to look at this, I was able to reproduce ir, but hadnt have much time on the mac box to check it. But it is on my radar so I will check asap
s
Btw, we tried to dive a little bit into it.. We realised that when we do a batch.flush() followed by a glFinish() in the Filter's render() method, the issue gets fixed.
but of course, the fps drops a lot..
d
I was able to reproduce it in a new macbook pro but doesnt reproduce on an older imac. It seems to be a bug in the gpu driver or something. Cant reproduce it either in linux or windows
Im still trying to figure out the exact cause to see if we can circumvent it
s
We're developing for the iOS and Android.. Can definitely reproduce it on Android. GL ES3.0
d
glFlush instead of glFinish, helps?
Copy code
val bitmap = resourcesVfs["korge.png"].readBitmap()
val blur = BlurFilter(initialRadius = 0.0)
image(bitmap).also { it.filter = blur }
timeout(40.milliseconds) { blur.radius = 1.0 }
this reproduces the issue in a macbook with a Radeon Pro 5300M
gl finishing doesn’t fixes the issue here in my case
managed to fix it on the mac
can you check if this commit fixes the android issue too? https://github.com/korlibs/korge-next/commit/559ef4e7519b33001d7c7cfc4d6ba783de98d947
👍 1
m
I tried running the sample. It works perfectly with runNativeDebug. But I’m seeing issues with jvm and js targets. On jvm, it is running smoothly now but some artifacts are observed in the flag filter On js, some filters stopped working Attaching videos
p
I have a question: does each image have it's own context, or does the program create a single context and share between images?
s
@Deactivated User I can still reproduce the issue on Android. Only gets fixed with glFinish
Scene:
Copy code
override suspend fun Container.sceneMain() {

    repeat(5) {
        val image = Image(resourcesVfs["korge.png"].readBitmap().slice())

        image.pos = Point(it * 200.0, it * 300.0)

        repeat(1) {
            val filter = IdentityFilter(false)
            image.addFilter(filter)
        }

        this.addChild(image)
    }
}
p
We did a GPU trace, and found that texImage2D was being called every frame due to dirty flag always being set to true, so we tested only setting dirty when texture changes size, and it resolved our issues with both crash and slow FPS. the commit is in this link, perhaps you could look at it and see if there's a cleaner solution of if this suffices https://github.com/invideoio/korge-next/commit/95edff817d48d3a00ce1ae15169d0689a74d7eeb
d
Nice! Can you make a PR?
s
@Deactivated User Is this good to go?
d
@Sahil Bajaj I have been pretty busy this weekend. Ill check today!
s
No worries... :) At your convenience.