Skip to content

[macOS] Piko becomes unresponsive when opening a video in the built-in player #69

Backlog

Description

@K-MarkLee

Environment

  • Piko 1.7.0
  • macOS 27.2.1
  • Apple M3 Max (arm64)

What's the problem?

When I open a video in Piko's built-in player, the entire app becomes unresponsive. I have to force quit Piko to use it again.

I reviewed the playback options under Settings → Browsing & playback. The freeze occurs with both Hardware decoding and Software.
It also occurs at the lowest available playback quality and after clearing the app cache.

piko-log-20261202-104512.txt

Activity

  1. NihilDigit commented on Dec 2, 2026

    @NihilDigit
    Owner

    Thanks for the report and log!
    To pinpoint where it's hanging, could you capture a process sample while Piko is unresponsive?

    • Reproduce the freeze.
    • Open Activity Monitor, select Piko, and click the ... menu → Sample Process (or run sample $(pgrep -x Piko) 5 -file ~/Desktop/piko-sample.txt in Terminal).
    • Attach the saved sample file here.
      If you can also check whether opening an audio file or using an external player works normally, that would help us narrow it down further.
  2. YSoung99 commented on Dec 2, 2026

    @YSoung99

    I hit the same freeze on 1.7.0 (macOS 27.3, Apple M4) right after opening the clip feed / a preview player window, and captured a sample while Piko was unresponsive. It looks like an AppKit main thread ↔ EDT deadlock in the title bar setup.

    Sample (relevant threads, 815/815 samples identical):

    Thread: AWT-EventQueue-0
      Java_org_jetbrains_skiko_PlatformOperationsKt_osxDisableTitleBar  (libskiko-macos-arm64.dylib)
      -[LayerHandler disableTitlebar:]  (libskiko-macos-arm64.dylib)
      _dispatch_sync_f_slow  (libdispatch.dylib)
      __DISPATCH_WAIT_FOR_QUEUE__  (libdispatch.dylib)
      _dispatch_thread_main_event_wait_slow  (libdispatch.dylib)
    
    Thread: main (com.apple.main-thread)
      Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoopImpl  (libawt_lwawt.dylib)
      -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
      __CFRunLoopRun → mach_msg (idle)
    

    What I think is happening

    • MacTitleBarEffect calls SkiaLayer.disableTitleBar() from a LaunchedEffect, i.e. on the EDT.
    • Skiko's native -[LayerHandler disableTitlebar:] (Drawlayer.mm, v0.156.1) does dispatch_sync(dispatch_get_main_queue(), …).
    • If at that moment the AppKit main thread is inside LWCToolkit.doAWTRunLoop (the nested run loop used by LWCToolkit.invokeAndWait, running in javaRunLoopMode, which does not drain the GCD main queue), it is waiting for the EDT while the EDT is waiting for the main queue → permanent deadlock. The process stays alive (background sync keeps logging) but the UI never recovers.
    • It is timing dependent, which fits it happening when a new window (player / clip preview) is shown.

    Workaround I tested locally

    Call disableTitleBar off the EDT so only a background thread blocks on dispatch_sync; the main thread can finish its nested loop, return to the default mode and then run the block:

    --- a/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt
    +++ b/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt
    @@ -66,7 +66,9 @@
     import java.awt.Container
    +import kotlinx.coroutines.Dispatchers
     import kotlinx.coroutines.delay
    +import kotlinx.coroutines.withContext
    @@ -600,7 +602,8 @@ private fun FrameWindowScope.MacTitleBarEffect() {
         LaunchedEffect(window) {
             while (!window.isShowing) delay(16)
    -        findSkiaLayer(window)?.disableTitleBar(TitleBarHeight.value)
    +        val layer = findSkiaLayer(window)
    +        if (layer != null) withContext(Dispatchers.IO) { layer.disableTitleBar(TitleBarHeight.value) }
             MacOs.patchTitleBarDoubleClick()
         }
     }

    I built :desktopApp from the v1.7.0 tag with this change, swapped the two changed classes into my installed 1.7.0 jar, and the app starts normally with the title bar applied as before. Since the bug is timing dependent I can't prove a negative yet; I'll report back if it freezes again.

    One caveat: the native osxDisableTitleBar looks up the layer by iterating Skiko's global layerStorage (NSMutableSet), which is otherwise mutated on the EDT when layers are created/disposed, so calling it off the EDT has a small theoretical race. A cleaner long-term fix might be in Skiko itself (e.g. dispatch_async, or not blocking when the caller is the EDT), but the change above seems like a low-risk mitigation for Piko.

  3. NihilDigit commented on Dec 2, 2026

    @NihilDigit
    Owner

    I hit the same freeze on 1.7.0 (macOS 27.3, Apple M4) right after opening the clip feed / a preview player window, and captured a sample while Piko was unresponsive. It looks like an AppKit main thread ↔ EDT deadlock in the title bar setup.

    Sample (relevant threads, 815/815 samples identical):

    Thread: AWT-EventQueue-0
      Java_org_jetbrains_skiko_PlatformOperationsKt_osxDisableTitleBar  (libskiko-macos-arm64.dylib)
      -[LayerHandler disableTitlebar:]  (libskiko-macos-arm64.dylib)
      _dispatch_sync_f_slow  (libdispatch.dylib)
      __DISPATCH_WAIT_FOR_QUEUE__  (libdispatch.dylib)
      _dispatch_thread_main_event_wait_slow  (libdispatch.dylib)
    
    Thread: main (com.apple.main-thread)
      Java_sun_lwawt_macosx_LWCToolkit_doAWTRunLoopImpl  (libawt_lwawt.dylib)
      -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
      __CFRunLoopRun → mach_msg (idle)
    

    What I think is happening

    • MacTitleBarEffect calls SkiaLayer.disableTitleBar() from a LaunchedEffect, i.e. on the EDT.
    • Skiko's native -[LayerHandler disableTitlebar:] (Drawlayer.mm, v0.156.1) does dispatch_sync(dispatch_get_main_queue(), …).
    • If at that moment the AppKit main thread is inside LWCToolkit.doAWTRunLoop (the nested run loop used by LWCToolkit.invokeAndWait, running in javaRunLoopMode, which does not drain the GCD main queue), it is waiting for the EDT while the EDT is waiting for the main queue → permanent deadlock. The process stays alive (background sync keeps logging) but the UI never recovers.
    • It is timing dependent, which fits it happening when a new window (player / clip preview) is shown.

    Workaround I tested locally

    Call disableTitleBar off the EDT so only a background thread blocks on dispatch_sync; the main thread can finish its nested loop, return to the default mode and then run the block:

    --- a/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt
    +++ b/desktopApp/src/desktopMain/kotlin/dev/piko/desktop/WindowFrame.kt
    @@ -66,7 +66,9 @@
    import java.awt.Container
    +import kotlinx.coroutines.Dispatchers
    import kotlinx.coroutines.delay
    +import kotlinx.coroutines.withContext
    @@ -600,7 +602,8 @@ private fun FrameWindowScope.MacTitleBarEffect() {
    LaunchedEffect(window) {
    while (!window.isShowing) delay(16)

    •    findSkiaLayer(window)?.disableTitleBar(TitleBarHeight.value)
      
    •    val layer = findSkiaLayer(window)
      
    •    if (layer != null) withContext(Dispatchers.IO) { layer.disableTitleBar(TitleBarHeight.value) }
         MacOs.patchTitleBarDoubleClick()
      
      }
      }
      I built :desktopApp from the v1.7.0 tag with this change, swapped the two changed classes into my installed 1.7.0 jar, and the app starts normally with the title bar applied as before. Since the bug is timing dependent I can't prove a negative yet; I'll report back if it freezes again.

    One caveat: the native osxDisableTitleBar looks up the layer by iterating Skiko's global layerStorage (NSMutableSet), which is otherwise mutated on the EDT when layers are created/disposed, so calling it off the EDT has a small theoretical race. A cleaner long-term fix might be in Skiko itself (e.g. dispatch_async, or not blocking when the caller is the EDT), but the change above seems like a low-risk mitigation for Piko.

    Thanks a lot for digging into this and capturing the sample!

    Your approach looks good as a workaround on Piko's side. If it holds up in your testing, would you be up for opening a PR?

  4. K-MarkLee commented on Dec 2, 2026

    @K-MarkLee
    Author

    Thanks for sharing the sample and the workaround.
    I’ll test calling disableTitleBar() after pack() and before showing the player window, following Skiko’s AWT example.
    If it holds up after repeatedly opening and closing the player on my Mac, I’ll share the results here and open a PR with the change.

  5. K-MarkLee commented on Dec 2, 2026

    @K-MarkLee
    Author

    Thanks for digging into this, @YSoung99. I tried following the Skiko AWT sample by calling window.pack() before disableTitleBar() and before showing the window. On my macOS setup with JDK 25, calling pack() that early caused problems during Piko’s window initialization. Skiko AWT sample

    I think your approach of moving disableTitleBar() off the EDT is the most practical workaround for Piko right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions