Skip to content

UI corruption at startup #505

Closed
Closed

Description

@flyingmutant

CC @mahkoh

Expected:
2016-08-25 22 52 07

Actual:
2016-08-25 22 52 14

Ctrl-L fixes the glitches.

gp@MacBook-Pro-Gregory ~/d/cmus ((5969d12...)|BISECTING) [1]> git bisect log
git bisect start
# good: [9d37708a93c9fadeebe0eb9f8f67310e4fe55156] Merge pull request #475 from mahkoh/set_priority3
git bisect good 9d37708a93c9fadeebe0eb9f8f67310e4fe55156
# bad: [04836a121a1cba1950cb35371e3f8e46bbad74e1] Merge branch 'get_opt' of https://github.com/mahkoh/cmus into mahkoh-get_opt
git bisect bad 04836a121a1cba1950cb35371e3f8e46bbad74e1
# skip: [99e98f7330fef891b18a3d09e8dad921f1be85da] Add some wrapper functions to pl.c
git bisect skip 99e98f7330fef891b18a3d09e8dad921f1be85da
# skip: [4ae58951734e69c5ffe33192e33c10cff16d10d2] Use pl wrappers in command_mode.c
git bisect skip 4ae58951734e69c5ffe33192e33c10cff16d10d2
# bad: [da54f6dc59e906387fc8d2c589a2ea4998542a8e] Rename pl_clear_pl to pl_clear_visible_pl
git bisect bad da54f6dc59e906387fc8d2c589a2ea4998542a8e
# bad: [7262540b61dc1d43607215faa18456669c9e07fc] Use pl wrapper functions in ui_curses.c
git bisect bad 7262540b61dc1d43607215faa18456669c9e07fc
# bad: [4b54422c1e80e67fe8353988b178578c569dc832] Restore "continue" feature
git bisect bad 4b54422c1e80e67fe8353988b178578c569dc832
# good: [3ebe81b815e8b3b535cb23dd1869e0fbfdb34385] Add convenience macro for select
git bisect good 3ebe81b815e8b3b535cb23dd1869e0fbfdb34385
# good: [4a2ae75b27a920a8487b04f9abf35eb1761298fe] Fix a memory leak in free_update_job
git bisect good 4a2ae75b27a920a8487b04f9abf35eb1761298fe
# bad: [8fec8b59aed2ff32363508a3b795ee1a9f7cd4a7] Change jobs to use the async interface
git bisect bad 8fec8b59aed2ff32363508a3b795ee1a9f7cd4a7
# good: [5969d122a2da7b0a85256d042887e8c2b91f4ed7] Add multi-thread track requests
git bisect good 5969d122a2da7b0a85256d042887e8c2b91f4ed7
# first bad commit: [8fec8b59aed2ff32363508a3b795ee1a9f7cd4a7] Change jobs to use the async interface

Activity

  1. mahkoh commented on Aug 25, 2016

    @mahkoh
    Member

    I'll look into it.

  2. mahkoh commented on Aug 25, 2016

    @mahkoh
    Member

    I have not seen this myself. How can I reproduce it?

  3. flyingmutant commented on Aug 25, 2016

    @flyingmutant
    MemberAuthor

    It occurs immediately after starting cmus. I can reproduce it 100% of the time. Maybe some initial draw / cache loading race?

  4. mahkoh commented on Aug 25, 2016

    @mahkoh
    Member

    Try this patch on master

    diff --git a/options.c b/options.c
    index 0f14ca1..3100695 100644
    --- a/options.c
    +++ b/options.c
    @@ -77,7 +77,7 @@ int display_artist_sort_name;
     int smart_artist_sort = 1;
     int scroll_offset = 2;
     int rewind_offset = 5;
    -int skip_track_info = 0;
    +_Atomic int skip_track_info = 0;
     int auto_expand_albums_follow = 1;
     int auto_expand_albums_search = 1;
     int auto_expand_albums_selcur = 1;
    @@ -1019,7 +1019,9 @@ static void get_skip_track_info(void *data, char *buf, size_t size)
    
     static void set_skip_track_info(void *data, const char *buf)
     {
    -   parse_bool(buf, &skip_track_info);
    +   int tmp = skip_track_info;
    +   parse_bool(buf, &tmp);
    +   skip_track_info = tmp;
     }
    
     static void toggle_skip_track_info(void *data)
    diff --git a/options.h b/options.h
    index 113a6de..e9fc554 100644
    --- a/options.h
    +++ b/options.h
    @@ -138,7 +138,7 @@ extern int display_artist_sort_name;
     extern int smart_artist_sort;
     extern int scroll_offset;
     extern int rewind_offset;
    -extern int skip_track_info;
    +extern _Atomic int skip_track_info;
     extern int mouse;
     extern int mpris;
    
    diff --git a/track_info.c b/track_info.c
    index 00ead95..e483c3e 100644
    --- a/track_info.c
    +++ b/track_info.c
    @@ -28,6 +28,7 @@
     #include "ui_curses.h"
    
     #include <string.h>
    +#include <stdatomic.h>
     #include <math.h>
    
     static void track_info_free(struct track_info *ti)
    @@ -110,15 +111,15 @@ void track_info_set_comments(struct track_info *ti, struct keyval *comments) {
    
     void track_info_ref(struct track_info *ti)
     {
    -   BUG_ON(ti->ref < 1);
    -   ti->ref++;
    +   int prev = atomic_fetch_add(&ti->ref, 1);
    +   BUG_ON(prev < 1);
     }
    
     void track_info_unref(struct track_info *ti)
     {
    -   BUG_ON(ti->ref < 1);
    -   ti->ref--;
    -   if (ti->ref == 0)
    +   int prev = atomic_fetch_sub(&ti->ref, 1);
    +   BUG_ON(prev < 1);
    +   if (prev == 1)
            track_info_free(ti);
     }
    
    diff --git a/track_info.h b/track_info.h
    index 41f406d..4f14ffd 100644
    --- a/track_info.h
    +++ b/track_info.h
    @@ -35,7 +35,7 @@ struct track_info {
        long bitrate;
        char *codec;
        char *codec_profile;
    -   int ref;
    +   _Atomic int ref;
        char *filename;
    
        int tracknumber;
  5. mahkoh commented on Aug 25, 2016

    @mahkoh
    Member

    I've updated the patch above.

  6. flyingmutant commented on Aug 26, 2016

    @flyingmutant
    MemberAuthor

    The patch above does not help.

  7. mahkoh commented on Aug 26, 2016

    @mahkoh
    Member

    I can't find the problem because I cannot reproduce this.

  8. flyingmutant commented on Aug 26, 2016

    @flyingmutant
    MemberAuthor

    How big is your music collection? My wild guess is it may have something to do with cache loading time (I can not reproduce the issue with empty library).

  9. mahkoh commented on Aug 26, 2016

    @mahkoh
    Member

    My cache file is 1.4M loaded from an HD. But I don't think that is the cause because the cache is loaded in the UI thread before anything is drawn and before the worker thread is initialized. Maybe try this

    diff --git a/ui_curses.c b/ui_curses.c
    index 4cfc35e..2507c83 100644
    --- a/ui_curses.c
    +++ b/ui_curses.c
    @@ -2341,8 +2341,8 @@ static void init_all(void)
    
        lib_init();
        searchable = tree_searchable;
    -   pl_init();
        cmus_init();
    +   pl_init();
        browser_init();
        filters_init();
        help_init();

    To me this looks like memory corruption because drawing the library will always draw the separator. And drawing any of the windows will always draw the title. Maybe put some printfs in update_window.

  10. flyingmutant commented on Aug 26, 2016

    @flyingmutant
    MemberAuthor

    2016-08-26 22 59 14

    I don't have time to dig into this right now — will look into this during the weekend.

    bash-3.2$ ASAN_OPTIONS=detect_odr_violation=0 cmus
    =================================================================
    ==8771==ERROR: AddressSanitizer: global-buffer-overflow on address 0x000109d02248 at pc 0x000104f2bbf3 bp 0x7fff5ad2b390 sp 0x7fff5ad2b388
    READ of size 8 at 0x000109d02248 thread T0
        #0 0x104f2bbf2 in op_add_options output.c:411
        #1 0x104f5695e in main ui_curses.c:2340
        #2 0x7fff8bf105ac in start (libdyld.dylib+0x35ac)
        #3 0x0  (<unknown module>)
    
    0x000109d02248 is located 0 bytes to the right of global variable 'op_pcm_options' defined in 'jack.c:623:32' (0x109d02200) of size 72
    0x000109d02248 is located 72 bytes inside of global variable 'op_pcm_options' defined in 'coreaudio.c:863:32' (0x109d02200) of size 96
    0x000109d02248 is located 72 bytes inside of global variable 'op_pcm_options' defined in 'ao.c:298:32' (0x109d02200) of size 144
    SUMMARY: AddressSanitizer: global-buffer-overflow output.c:411 in op_add_options
    Shadow bytes around the buggy address:
      0x1000213a03f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x1000213a0400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x1000213a0410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x1000213a0420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x1000213a0430: 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9
    =>0x1000213a0440: 00 00 00 00 00 00 00 00 00[f9]f9 f9 f9 f9 f9 f9
      0x1000213a0450: 00 00 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
      0x1000213a0460: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x1000213a0470: 00 00 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
      0x1000213a0480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x1000213a0490: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07 
      Heap left redzone:       fa
      Heap right redzone:      fb
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack partial redzone:   f4
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
    ==8771==ABORTING
    Abort trap: 6
    
  11. mahkoh commented on Aug 26, 2016

    @mahkoh
    Member

    Unfortunately asan doesn't work with the latest glibc so I cannot test it myself. https://sourceware.org/bugzilla/show_bug.cgi?id=20069

  12. mahkoh commented on Oct 8, 2016

    @mahkoh
    Member

    Can anyone besides @flyingmutant reproduce this?

  13. mahkoh commented on Oct 18, 2016

    @mahkoh
    Member

    Asan works again in GCC and finds absolutely nothing wrong with cmus. What it did find is that pulse leaks some memory.

  14. changed the title [-]UI corruption started with 8fec8b59aed2ff32363508a3b795ee1a9f7cd4a7[/-] [+]UI corruption at startup[/+] on Nov 5, 2016
  15. jayay commented on Feb 5, 2017

    @jayay
    Contributor

    @flyingmutant does this still occur after 055094c?

  16. An7ar35 commented on Jan 13, 2018

    @An7ar35

    Maybe related but as I scroll through my library, old characters belonging to names longer than the ones selected stay on screen on v2.7.1-8.

    This behaviour does not happen on my desktop (Arch Linux/Nvidia using nvidia 387.34-19) but happens on the laptop (Arch Linux/Radeon using xf86-video-amdgpu 1.4.0-1).

  17. pgaskin commented on Sep 20, 2024

    @pgaskin
    Member

    I think this has been fixed.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions