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

"Invalid Pointer" error when opening (some) zipped roms #4063

Closed
bmn001 opened this issue Nov 24, 2016 · 43 comments
Closed

"Invalid Pointer" error when opening (some) zipped roms #4063

bmn001 opened this issue Nov 24, 2016 · 43 comments

Comments

@bmn001
Copy link

bmn001 commented Nov 24, 2016

I'm running the latest compiled RetroArch with Retropie on a Raspberry Pi 3.

Some (not all) zipped roms will produce an "Invalid Pointer" error when I attempt to launch them from the command line:
*** Error in `/opt/retropie/emulators/retroarch/bin/retroarch': free(): invalid pointer: 0x01ff8979 ***

If unzipped, these roms launch without error. It's only when they're zipped that I run into trouble with some of them.

Here's an example of the error popping up within lr-fceumm:
http://pastebin.com/C36xN96W

And an example of a rom working properly in the same environment with the same launch command:
http://pastebin.com/7hwpgJxC

These zipped roms worked properly in previous versions of RetroArch. Maybe six months ago? Hard to say for certain.

I'm happy to provide any additional information you need to help track this down.

@lpcardinal
Copy link

I have the same issue with a similar setup. When I unzip the roms, everythings runs fine.

@magus424
Copy link

I've got a weird case of this to add to the pile...

I have the exact same zip in two locations; a list of favorites in the root of the nes dir;

/home/pi/RetroPie/roms/nes/Adventures of Lolo (USA).zip

And then also in the larger group of all files;

/home/pi/RetroPie/roms/nes/!All/A/Adventures of Lolo (USA).zip

The first location in nes/ gives an invalid pointer error, while the second in nes/!All/A/ works perfectly fine.

If I unzip the file and zip it with 0% compression (aka store-only), then the error goes away.

@inactive123
Copy link
Contributor

We need a stack trace of this, this isn't really telling us much.

@magus424
Copy link

magus424 commented Dec 19, 2016

If you can point me at directions on how to do that, I'd be happy to give it a shot.

edit: wait, managed to figure out a little bit in gdb if this is helpful at all:

#0  0x769eaf70 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x769ec324 in __GI_abort () at abort.c:89
#2  0x76a26954 in __libc_message (do_abort=<optimized out>, fmt=0x76adc6e8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
#3  0x76a2cb80 in malloc_printerr (action=1, str=0x76adc8ec "free(): invalid pointer", ptr=<optimized out>) at malloc.c:4996
#4  0x76a2db24 in _int_free (av=<optimized out>, p=<optimized out>, have_lock=1959192) at malloc.c:3840
#5  0x75efa450 in FCEU_KillVirtualVideo () from /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so
#6  0x75efa46c in FCEUI_Kill () from /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so
#7  0x75efa488 in retro_deinit () from /opt/retropie/libretrocores/lr-fceumm/fceumm_libretro.so
#8  0x0001fe1c in core_unload () at core_impl.c:374
#9  0x00026ac0 in command_event_deinit_core (reinit=true) at command.c:1193
#10 command_event (cmd=cmd@entry=CMD_EVENT_CORE_DEINIT, data=data@entry=0x0) at command.c:2160
#11 0x000228cc in retroarch_main_init (argc=0, argv=0x0, argv@entry=0x7efff634) at retroarch.c:1101
#12 0x00038594 in content_load (info=0x225068) at tasks/task_content.c:281
#13 task_load_content (content_info=content_info@entry=0x7efff4b8, launched_from_menu=launched_from_menu@entry=false, mode=CONTENT_MODE_LOAD_FROM_CLI) at tasks/task_content.c:903
#14 0x00039648 in task_push_content_load_default (core_path=core_path@entry=0x0, fullpath=fullpath@entry=0x0, content_info=0x7efff4b8, content_info@entry=0x7efff4b0, type=type@entry=CORE_TYPE_PLAIN,
    mode=mode@entry=CONTENT_MODE_LOAD_FROM_CLI, cb=cb@entry=0x0, user_data=user_data@entry=0x0) at tasks/task_content.c:1283
#15 0x0001f02c in rarch_main (argc=6, argv=0x7efff634, data=0x0) at frontend/frontend.c:113
#16 0x769d5294 in __libc_start_main (main=0x7efff634, argc=1991221248, argv=0x769d5294 <__libc_start_main+276>, init=<optimized out>, fini=0x11d908 <__libc_csu_fini>, rtld_fini=0x76fdf408 <_dl_fini>, stack_end=0x7efff634)
    at libc-start.c:287

@chr0m
Copy link

chr0m commented Dec 29, 2016

I'm getting this issue too and it is bizarre. I don't understand why zipping the non-working games with zero compression makes them work, but it does. In both cases the .nes is being unzipped correctly to /tmp/retroarch.

Also if you put verbose output on you can see that information is being read from the rom in /tmp/retroarch before the invalid pointer exception.

I have another retropie setup on a different SD card with EXACTLY the same versions of the retroarch and fceumm_libretro.so binaries and all the same .cfg and .sh files, the same kernel version and I don't have this issue there.

@angiolucci
Copy link

angiolucci commented Dec 31, 2016

The same issue here. Some zipped roms work, some don't. The problematic zipped roms used to work two weeks ago (with the raw retropie-4.1-rpi2_rpi3.img), I don't know what's changed (I've done a couple of system updates since that date). I tried fsck on my SD card and I also checked the zip files integrity, everything seems to be OK. If I unzip them, it works nice. If I zip them with a shorter name , it also works.
Example: "Donkey Kong (World) (Rev A).zip" don't work, but "dk.zip" (with a dk.nes file inside it) works.
Zip compression level seems not to be the problem, since '-9 zipped' roms will fail as '-0 zipped' ones.

@ghost
Copy link

ghost commented Dec 31, 2016

I found the issue, it was a regression in the core and I have fixed it in libretro/libretro-fceumm@821ca02.

@joolswills
Copy link
Contributor

I'm still getting the issue unfortunately even since @bparker06 patch - will bisect.

@ghost
Copy link

ghost commented Jan 2, 2017

@joolswills As a sanity check can you just confirm that the git version shown at the bottom-left of the RA menu is indeed 89ce055?

@joolswills
Copy link
Contributor

Yes. It's related to the RetroArch version - I have it working with a build of RetroArch from a few weeks ago (currently bisecting).

@joolswills
Copy link
Contributor

joolswills commented Jan 2, 2017

./retroarch -L ../libretro-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].zip" --verbose --appendconfig /dev/shm/retroarch.cfg
RetroArch [INFO] :: Redirecting save file to "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].srm".
RetroArch [INFO] :: === Build =======================================
Capabilities: NEON VFPv3 VFPv4 
Built: Jan  2 2017
RetroArch [INFO] :: Version: 1.3.6
RetroArch [INFO] :: Git: 9b2270f
RetroArch [INFO] :: =================================================
RetroArch [INFO] :: Config: loading config from: /opt/retropie/configs/nes/retroarch.cfg.
RetroArch [INFO] :: Config: appending config "/dev/shm/retroarch.cfg"
RetroArch [INFO] :: Incompatible shader for backend gl, clearing...
RetroArch [INFO] :: Resetting undo buffers.
RetroArch [INFO] :: Loading dynamic libretro core from: "/home/pi/libretro-fceumm/fceumm_libretro.so"
RetroArch [INFO] :: [overrides] no core-specific overrides found at /home/pi/.config/retroarch/config/FCEUmm/FCEUmm.cfg.
RetroArch [INFO] :: [overrides] no game-specific overrides found at /home/pi/.config/retroarch/config/FCEUmm/Super Mario Bros. (JU) [!].cfg.
RetroArch [INFO] :: Shaders: preset directory: /home/pi/.config/retroarch/shaders/presets
RetroArch [INFO] :: Shaders: no game-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/Super Mario Bros. (JU) [!].cgp.
RetroArch [INFO] :: Shaders: no game-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/Super Mario Bros. (JU) [!].glslp.
RetroArch [INFO] :: Shaders: no core-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/FCEUmm.cgp.
RetroArch [INFO] :: Shaders: no core-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/FCEUmm.glslp.
RetroArch [INFO] :: Environ SET_VARIABLES.
RetroArch [INFO] :: Remaps: remap directory: /opt/retropie/configs/nes/
RetroArch [INFO] :: Remaps: no game-specific remap found at /opt/retropie/configs/nes/FCEUmm/Super Mario Bros. (JU) [!].rmp.
RetroArch [INFO] :: Remaps: no core-specific remap found at /opt/retropie/configs/nes/FCEUmm/FCEUmm.rmp.
RetroArch [INFO] :: Redirecting save file to "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].srm".
RetroArch [INFO] :: Environ GET_LOG_INTERFACE.
RetroArch [INFO] :: Environ SET_PIXEL_FORMAT: RGB565.
RetroArch [libretro INFO] :: Frontend supports RGB565 - will use that instead of XRGB1555.
RetroArch [INFO] :: Environ PERFORMANCE_LEVEL: 5.
RetroArch [INFO] :: Content loading skipped. Implementation will load it on its own.
RetroArch [INFO] :: Environ SET_INPUT_DESCRIPTORS:
RetroArch [INFO] :: 	RetroPad, User 1, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 1, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 1, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 1, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 1, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 1, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: 	RetroPad, User 1, Button "L" => "(FDS) Disk Side Change"
RetroArch [INFO] :: 	RetroPad, User 1, Button "R" => "(FDS) Insert/Eject Disk"
RetroArch [INFO] :: 	RetroPad, User 1, Button "R2" => "(VSSystem) Insert Coin"
RetroArch [INFO] :: 	RetroPad, User 2, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 2, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 2, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 2, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 2, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 2, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: 	RetroPad, User 3, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 3, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 3, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 3, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 3, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 3, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: 	RetroPad, User 4, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 4, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 4, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 4, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 4, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 4, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: Environ SYSTEM_DIRECTORY: "/home/pi/RetroPie/BIOS".
RetroArch [libretro INFO] :: Loading /tmp/retroarch/Super Mario Bros. (JU) [!].nes...

RetroArch [libretro INFO] ::  PRG ROM:    2 x 16KiB
RetroArch [libretro INFO] ::  CHR ROM:    1 x  8KiB
RetroArch [libretro INFO] ::  ROM CRC32:  0xd445f698
RetroArch [libretro INFO] ::  ROM MD5:  0x8e3630186e35d477231bf8fd50e54cdd
RetroArch [libretro INFO] ::  Mapper #:  0
RetroArch [libretro INFO] ::  Mapper name: NROM
RetroArch [libretro INFO] ::  Mirroring: Vertical
RetroArch [libretro INFO] ::  Battery-backed: No
RetroArch [libretro INFO] ::  Trained: No
RetroArch [libretro INFO] :: 
RetroArch [INFO] :: Environ GET_VARIABLE fceumm_palette:
RetroArch [INFO] :: 	asqrealc
RetroArch [INFO] :: Environ GET_VARIABLE fceumm_nospritelimit:
RetroArch [INFO] :: 	disabled
RetroArch [INFO] :: Environ GET_VARIABLE fceumm_overclocking:
RetroArch [INFO] :: 	disabled
*** Error in `./retroarch': free(): invalid pointer: 0x012e654a ***
Aborted

bisected to 9b2270f

commit 9b2270f5d4cc20fa1c9270d5e1cf64a7443d2dfc
Author: Gregor Richards <hg-yff@gregor.im>
Date:   Fri Dec 9 23:04:39 2016 -0500

    Say goodbye to spectator mode (for now)

:100644 100644 c81cf37b9182facef3bbe1d7291f898c9480a317 5b20704103c1a810fe55cf9feca46f669defa418 M	Makefile.common
:100644 100644 6eefad0f0261fec481b97b37cd615b86fc3057ca 8676b49c6da0a9bd93a0a641906a0ca8aedd3b06 M	command.c
:100644 100644 0f6ee0a82ccfbb9ff89629b1c93041e69ae88ee4 b869a84f66141b4d8eae2ed51bcab9815882918c M	configuration.c
:100644 100644 d4cc94cf917e4a22eb9ee0b320b7e17633118588 85093933a1530937fe073837282491e3ba9d2ea0 M	configuration.h
:040000 040000 e14c75fcfd46419d0318ec97a4a7f5639695d050 01a322e143bbcf96fe2cece2c58df0e9ea6719b8 M	menu
:040000 040000 b3a1bbf6248ed5ce11d69f83f32ad14fee19bbc9 fd6cb4c8b81966f916f5bce1978386e86ef43bd5 M	network
:100644 100644 af54841baa4e74ba6b20caed3fe1f6d22d01da14 380c5dbdde500aa8e92c67e548a9a44e480fd67e M	retroarch.c

@ghost
Copy link

ghost commented Jan 2, 2017

Can you get a backtrace of the crash? Or even better, a valgrind output as well?

@joolswills
Copy link
Contributor

Yep. working on it.

@ghost
Copy link

ghost commented Jan 2, 2017

I guess there happen to be two separate problems at play here. I cannot reproduce the free() crash you're seeing, but the problems in the core were definitely real (and fixed my own crashes loading certain zips), so that's fun.

@joolswills
Copy link
Contributor

#0  0x7695bf70 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
        _sys_result = <optimized out>
        pd = 0x76ff0210
        pid = <optimized out>
        selftid = 4572
#1  0x7695d324 in __GI_abort () at abort.c:89
        save_stage = 2
        act = {__sigaction_handler = {sa_handler = 0x0, sa_sigaction = 0x0}, sa_mask = {__val = {0 <repeats 27 times>, 2130694096, 7, 85, 85, 
              2130694096}}, sa_flags = 7, sa_restorer = 0x55}
        sigs = {__val = {32, 0 <repeats 31 times>}}
#2  0x76997954 in __libc_message (do_abort=<optimized out>, fmt=0x76a4d6e8 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:175
        ap = {__ap = 0x7effd104}
        fd = 1
        on_2 = <optimized out>
        list = <optimized out>
        nlist = <optimized out>
        cp = <optimized out>
        written = <optimized out>
#3  0x7699db80 in malloc_printerr (action=1, str=0x76a4d8ec "free(): invalid pointer", ptr=<optimized out>) at malloc.c:4996
        buf = "0032b5e2"
        cp = <optimized out>
#4  0x7699eb24 in _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at malloc.c:3840
        size = <optimized out>
        fb = <optimized out>
        nextchunk = <optimized out>
        nextsize = <optimized out>
        nextinuse = <optimized out>
        prevsize = <optimized out>
        bck = <optimized out>
        fwd = <optimized out>
        errstr = <optimized out>
        locked = <optimized out>
        __func__ = "_int_free"
#5  0x75cafd44 in FCEU_KillVirtualVideo () at src/video.c:43
No locals.
#6  0x75c8f704 in check_variables () at src/drivers/libretro/libretro.c:894
        do_reinit = true
        overclock_state = 0
        var = {key = 0x75cc8e80 "fceumm_overclocking", value = 0x30aaf0 "disabled"}
        av_info = {geometry = {base_width = 0, base_height = 64, max_width = 3192368, max_height = 1976430884, aspect_ratio = 1.70021071e+38}, 
          timing = {fps = 1.368604336352982e-312, sample_rate = 2.8773086118671039e+259}}
        geometry_update = false
#7  0x75c90d50 in retro_load_game (game=0x30ba30) at src/drivers/libretro/libretro.c:1570
        i = 1996484608
        dir = 0x76731e04 "/home/pi/RetroPie/BIOS"
        fourscore_len = 42
        famicom_4p_len = 16
        desc = {{port = 0, device = 1, index = 0, id = 6, description = 0x75ccc9b4 "D-Pad Left"}, {port = 0, device = 1, index = 0, id = 4, 
            description = 0x75ccc9c0 "D-Pad Up"}, {port = 0, device = 1, index = 0, id = 5, description = 0x75ccc9cc "D-Pad Down"}, {port = 0, 
            device = 1, index = 0, id = 7, description = 0x75ccc9d8 "D-Pad Right"}, {port = 0, device = 1, index = 0, id = 0, 
            description = 0x75ccc9e4 "B"}, {port = 0, device = 1, index = 0, id = 8, description = 0x75ccc9e8 "A"}, {port = 0, device = 1, 
            index = 0, id = 2, description = 0x75ccc9ec "Select"}, {port = 0, device = 1, index = 0, id = 3, description = 0x75ccc9f4 "Start"}, {
            port = 0, device = 1, index = 0, id = 13, description = 0x75ccc9fc "(VSSystem) Insert Coin"}, {port = 0, device = 1, index = 0, 
            id = 10, description = 0x75ccca14 "(FDS) Disk Side Change"}, {port = 0, device = 1, index = 0, id = 11, 
            description = 0x75ccca2c "(FDS) Insert/Eject Disk"}, {port = 0, device = 1, index = 0, id = 9, description = 0x75ccca44 "Turbo A"}, {
            port = 0, device = 1, index = 0, id = 1, description = 0x75ccca4c "Turbo B"}, {port = 1, device = 1, index = 0, id = 6, 
            description = 0x75ccc9b4 "D-Pad Left"}, {port = 1, device = 1, index = 0, id = 4, description = 0x75ccc9c0 "D-Pad Up"}, {port = 1, 
            device = 1, index = 0, id = 5, description = 0x75ccc9cc "D-Pad Down"}, {port = 1, device = 1, index = 0, id = 7, 
            description = 0x75ccc9d8 "D-Pad Right"}, {port = 1, device = 1, index = 0, id = 0, description = 0x75ccc9e4 "B"}, {port = 1, 
            device = 1, index = 0, id = 8, description = 0x75ccc9e8 "A"}, {port = 1, device = 1, index = 0, id = 2, 
            description = 0x75ccc9ec "Select"}, {port = 1, device = 1, index = 0, id = 3, description = 0x75ccc9f4 "Start"}, {port = 1, device = 1, 
            index = 0, id = 9, description = 0x75ccca44 "Turbo A"}, {port = 1, device = 1, index = 0, id = 1, description = 0x75ccca4c "Turbo B"}, {
            port = 2, device = 1, index = 0, id = 6, description = 0x75ccc9b4 "D-Pad Left"}, {port = 2, device = 1, index = 0, id = 4, 
            description = 0x75ccc9c0 "D-Pad Up"}, {port = 2, device = 1, index = 0, id = 5, description = 0x75ccc9cc "D-Pad Down"}, {port = 2, 
            device = 1, index = 0, id = 7, description = 0x75ccc9d8 "D-Pad Right"}, {port = 2, device = 1, index = 0, id = 0, 
            description = 0x75ccc9e4 "B"}, {port = 2, device = 1, index = 0, id = 8, description = 0x75ccc9e8 "A"}, {port = 2, device = 1, 
            index = 0, id = 2, description = 0x75ccc9ec "Select"}, {port = 2, device = 1, index = 0, id = 3, description = 0x75ccc9f4 "Start"}, {
            port = 2, device = 1, index = 0, id = 9, description = 0x75ccca44 "Turbo A"}, {port = 2, device = 1, index = 0, id = 1, 
            description = 0x75ccca4c "Turbo B"}, {port = 3, device = 1, index = 0, id = 6, description = 0x75ccc9b4 "D-Pad Left"}, {port = 3, 
            device = 1, index = 0, id = 4, description = 0x75ccc9c0 "D-Pad Up"}, {port = 3, device = 1, index = 0, id = 5, 
            description = 0x75ccc9cc "D-Pad Down"}, {port = 3, device = 1, index = 0, id = 7, description = 0x75ccc9d8 "D-Pad Right"}, {port = 3, 
            device = 1, index = 0, id = 0, description = 0x75ccc9e4 "B"}, {port = 3, device = 1, index = 0, id = 8, description = 0x75ccc9e8 "A"}, {
            port = 3, device = 1, index = 0, id = 2, description = 0x75ccc9ec "Select"}, {port = 3, device = 1, index = 0, id = 3, 
            description = 0x75ccc9f4 "Start"}, {port = 3, device = 1, index = 0, id = 9, description = 0x75ccca44 "Turbo A"}, {port = 3, 
            device = 1, index = 0, id = 1, description = 0x75ccca4c "Turbo B"}, {port = 0, device = 0, index = 0, id = 0, description = 0x0}}
        additional_path_allocs = 0x30b620
#10 0x0003c2b8 in content_file_init (content_ctx=0x7effdb24, error_string=0x7effdb20) at tasks/task_content.c:746
        i = 0
        info = 0x30ba30
        content = 0x30a8d8
        ret = true
        special = 0x0
#11 0x0003d508 in content_init () at tasks/task_content.c:1416
        content_ctx = {subsystem = {data = 0x0, size = 0}, valid_extensions = 0x30a8c0 "fds|nes|unf|unif", 
          directory_cache = 0x30ab40 "/tmp/retroarch", directory_system = 0x30a928 "/home/pi/RetroPie/BIOS", history_list_enable = true, 
          block_extract = false, need_fullpath = true, set_supports_no_game_enable = true, temporary_content = 0x30af00}
        ret = true
        error_string = 0x0
        sys_info = 0x2b43b0 <runloop_system>
        settings = 0x7660d008
#12 0x00025e78 in event_init_content () at command.c:1330
No locals.
#13 0x00026048 in command_event_init_core (data=0x2a7128 <current_core_type>) at command.c:1395
        info = {env = 0x75b48 <rarch_environment_cb>}
        settings = 0x7660d008
#14 0x00027abc in command_event (cmd=CMD_EVENT_CORE_INIT, data=0x2a7128 <current_core_type>) at command.c:2219
        boolean = false
#15 0x0001f6f4 in retroarch_main_init (argc=7, argv=0x7efff2f4) at retroarch.c:1054
        init_failed = false
#16 0x0003b010 in content_load (info=0x7efff170) at tasks/task_content.c:275
        i = 1
        retval = true
        rarch_argc = 0
        rarch_argv = {0x0 <repeats 32 times>}
        argv_copy = {0x0 <repeats 32 times>}
        rarch_argv_ptr = 0x7efff2f4
        rarch_argc_ptr = 0x7efff170
        wrap_args = 0x30a068
#17 0x0003c580 in task_load_content (content_info=0x7efff170, content_ctx=0x7efff11c, launched_from_menu=false, mode=CONTENT_MODE_LOAD_FROM_CLI, 
    error_string=0x7efff118) at tasks/task_content.c:817
        name = "\000\064\001\000\020\301\327v\340\035\001\000\001\000\000\000\000\340\222v\020\373\377v\334\360\377~N4\001\000h\360\377~\236,]\242X\371\377vp\360\377~\304\360\377~\360\224\375vp\360\377~\264\372\377v\000\000\000\000\060\020\377v\001\000\000\000\000\000\000\000\001\000\000\000X\371\377v\270\360\377~%\000\000\000Դ\246v\022\\\002\000\220\340\022\000.\001\000\000\000\000\000\000\020\373\377v\001\000\000\000Դ\246v\377\377\377\377\000\000\000\000\260\276\327vP\213\377v\377\017\000\000\000\260\246v~\000\000\000\000\020\000\000\004\000\000\000p\t\000\000%\000\000\000\240\340\022\000.\001\000\000\272K\000\000\313\t\000\000X\371\377v\000\000\000\000\304=*\000\320\006"...
        msg = "\000\357\377~\214\221\375v\000\000\000\000\324\362\374v$\000\000\000\230\355\377v\000\000\000\000J-\025\002\000\360\377v\230\355\377v\270\357\377~`\310\376v\274\370\377v8\257\376v\000\000\000\000\000\000\000\000\001\000\000\000\016\000\000\000\260\033\377vh\365\377vA\276\223v\244\364\374vh\034\223v\001\000\000\000\000\000\000\000\330\\\377v,\360\377~A\276\223v\270\357\377~U\251\245B [\377v\300\357\377~\024\360\377~\360\224\375v\300\357\377~\264\372\377v\000\000\000\000\260\033\377v\001\000\000\000\000\000\000\000$\000\000\000\020\255\327v\000\000\000\000x\254\327v\320\357\377~\214\221\375v\330\357\377~\020\255\327v$\000\000\000\230\355\377v"...
#18 0x0003cff4 in task_push_content_load_default (core_path=0x0, fullpath=0x0, content_info=0x7efff170, type=CORE_TYPE_PLAIN, 
    mode=CONTENT_MODE_LOAD_FROM_CLI, cb=0x0, user_data=0x0) at tasks/task_content.c:1235
        content_ctx = {subsystem = {data = 0x0, size = 0}, valid_extensions = 0x0, directory_cache = 0x0, directory_system = 0x0, 
          history_list_enable = false, block_extract = false, need_fullpath = false, set_supports_no_game_enable = false, 
          temporary_content = 0x7efff144}
        loading_from_menu = false
        error_string = 0x0
        settings = 0x7660d008
#19 0x0001b550 in rarch_main (argc=7, argv=0x7efff2f4, data=0x0) at frontend/frontend.c:113
        info = {argc = 7, argv = 0x7efff2f4, args = 0x0, environ_get = 0x1ab08 <frontend_linux_get_env>}
        args = 0x0
#20 0x0001b608 in main (argc=7, argv=0x7efff2f4) at frontend/frontend.c:148
No locals.

@joolswills
Copy link
Contributor

Not sure if there is anything useful here (I don't have experience with valgrind - so feel free to ask me if you want another set of parameters)

valgrind --tool=memcheck --leak-check=full ./retroarch -L ../libretro-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].zip" --verbose --appendconfig /dev/shm/retroarch.cfg
==4971== Memcheck, a memory error detector
==4971== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==4971== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==4971== Command: ./retroarch -L ../libretro-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg /home/pi/RetroPie/roms/nes/Super\ Mario\ Bros.\ (JU)\ [!].zip --verbose --appendconfig /dev/shm/retroarch.cfg
==4971== 
RetroArch [INFO] :: Redirecting save file to "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].srm".
RetroArch [INFO] :: === Build =======================================
Capabilities: NEON VFPv3 VFPv4 
Built: Jan  2 2017
RetroArch [INFO] :: Version: 1.3.6
RetroArch [INFO] :: Git: f95759c
RetroArch [INFO] :: =================================================
RetroArch [INFO] :: Config: loading config from: /opt/retropie/configs/nes/retroarch.cfg.
RetroArch [INFO] :: Config: appending config "/dev/shm/retroarch.cfg"
RetroArch [INFO] :: Incompatible shader for backend gl, clearing...
RetroArch [INFO] :: Resetting undo buffers.
RetroArch [INFO] :: Loading dynamic libretro core from: "/home/pi/libretro-fceumm/fceumm_libretro.so"
==4971== Invalid read of size 4
==4971==    at 0x40197E0: strlen (strlen.S:76)
==4971==    by 0x400B6DB: _dl_new_object (dl-object.c:157)
==4971==    by 0x4005A5B: _dl_map_object_from_fd (dl-load.c:1059)
==4971==    by 0x4008D93: _dl_map_object (dl-load.c:2605)
==4971==    by 0x40143F7: dl_open_worker (dl-open.c:235)
==4971==    by 0x400FE93: _dl_catch_error (dl-error.c:187)
==4971==    by 0x4013D47: _dl_open (dl-open.c:661)
==4971==    by 0x4D90BA7: dlopen_doit (dlopen.c:66)
==4971==    by 0x400FE93: _dl_catch_error (dl-error.c:187)
==4971==    by 0x4D912A7: _dlerror_run (dlerror.c:163)
==4971==    by 0x4D90C73: dlopen@@GLIBC_2.4 (dlopen.c:87)
==4971==    by 0x73B63: dylib_load (dylib.c:79)
==4971==  Address 0x528ca3c is 0 bytes after a block of size 44 alloc'd
==4971==    at 0x4833970: malloc (vg_replace_malloc.c:263)
==4971==    by 0x400579B: local_strdup (dl-load.c:162)
==4971==    by 0x4008D17: _dl_map_object (dl-load.c:2538)
==4971==    by 0x40143F7: dl_open_worker (dl-open.c:235)
==4971==    by 0x400FE93: _dl_catch_error (dl-error.c:187)
==4971==    by 0x4013D47: _dl_open (dl-open.c:661)
==4971==    by 0x4D90BA7: dlopen_doit (dlopen.c:66)
==4971==    by 0x400FE93: _dl_catch_error (dl-error.c:187)
==4971==    by 0x4D912A7: _dlerror_run (dlerror.c:163)
==4971==    by 0x4D90C73: dlopen@@GLIBC_2.4 (dlopen.c:87)
==4971==    by 0x73B63: dylib_load (dylib.c:79)
==4971==    by 0x73FDB: load_dynamic_core (dynamic.c:245)
==4971== 
RetroArch [INFO] :: [overrides] no core-specific overrides found at /home/pi/.config/retroarch/config/FCEUmm/FCEUmm.cfg.
RetroArch [INFO] :: [overrides] no game-specific overrides found at /home/pi/.config/retroarch/config/FCEUmm/Super Mario Bros. (JU) [!].cfg.
RetroArch [INFO] :: Shaders: preset directory: /home/pi/.config/retroarch/shaders/presets
RetroArch [INFO] :: Shaders: no game-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/Super Mario Bros. (JU) [!].cgp.
RetroArch [INFO] :: Shaders: no game-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/Super Mario Bros. (JU) [!].glslp.
RetroArch [INFO] :: Shaders: no core-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/FCEUmm.cgp.
RetroArch [INFO] :: Shaders: no core-specific preset found at /home/pi/.config/retroarch/shaders/presets/FCEUmm/FCEUmm.glslp.
RetroArch [INFO] :: Environ SET_VARIABLES.
RetroArch [INFO] :: Remaps: remap directory: /opt/retropie/configs/nes/
RetroArch [INFO] :: Remaps: no game-specific remap found at /opt/retropie/configs/nes/FCEUmm/Super Mario Bros. (JU) [!].rmp.
RetroArch [INFO] :: Remaps: no core-specific remap found at /opt/retropie/configs/nes/FCEUmm/FCEUmm.rmp.
RetroArch [INFO] :: Redirecting save file to "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].srm".
RetroArch [INFO] :: Environ GET_LOG_INTERFACE.
RetroArch [INFO] :: Environ SET_PIXEL_FORMAT: RGB565.
RetroArch [libretro INFO] :: Frontend supports RGB565 - will use that instead of XRGB1555.
RetroArch [INFO] :: Environ PERFORMANCE_LEVEL: 5.
RetroArch [INFO] :: Content loading skipped. Implementation will load it on its own.
RetroArch [INFO] :: Environ SET_INPUT_DESCRIPTORS:
RetroArch [INFO] :: 	RetroPad, User 1, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 1, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 1, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 1, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 1, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 1, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 1, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: 	RetroPad, User 1, Button "L" => "(FDS) Disk Side Change"
RetroArch [INFO] :: 	RetroPad, User 1, Button "R" => "(FDS) Insert/Eject Disk"
RetroArch [INFO] :: 	RetroPad, User 1, Button "R2" => "(VSSystem) Insert Coin"
RetroArch [INFO] :: 	RetroPad, User 2, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 2, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 2, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 2, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 2, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 2, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 2, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: 	RetroPad, User 3, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 3, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 3, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 3, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 3, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 3, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 3, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: 	RetroPad, User 4, Button "B (bottom)" => "B"
RetroArch [INFO] :: 	RetroPad, User 4, Button "Y (left)" => "Turbo B"
RetroArch [INFO] :: 	RetroPad, User 4, Button "Select" => "Select"
RetroArch [INFO] :: 	RetroPad, User 4, Button "Start" => "Start"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Up" => "D-Pad Up"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Down" => "D-Pad Down"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Left" => "D-Pad Left"
RetroArch [INFO] :: 	RetroPad, User 4, Button "D-Pad Right" => "D-Pad Right"
RetroArch [INFO] :: 	RetroPad, User 4, Button "A (right)" => "A"
RetroArch [INFO] :: 	RetroPad, User 4, Button "X (up)" => "Turbo A"
RetroArch [INFO] :: Environ SYSTEM_DIRECTORY: "/home/pi/RetroPie/BIOS".
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460A4: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460B4: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460BC: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460C8: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460D0: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Use of uninitialised value of size 4
==4971==    at 0x48460D0: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460E4: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460EC: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460F0: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460F8: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== Conditional jump or move depends on uninitialised value(s)
==4971==    at 0x48460FC: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
RetroArch [libretro INFO] :: Loading /tmp/retroarch/Super Mario Bros. (JU) [!].nes...

disInstr(arm): unhandled instruction: 0xF1010200
                 cond=15(0xF) 27:20=16(0x10) 4:4=0 3:0=0(0x0)
==4971== valgrind: Unrecognised instruction at address 0x48426f4.
==4971==    at 0x48426F4: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== Your program just tried to execute an instruction that Valgrind
==4971== did not recognise.  There are two possible reasons for this.
==4971== 1. Your program has a bug and erroneously jumped to a non-code
==4971==    location.  If you are running Memcheck and you just saw a
==4971==    warning about a bad jump, it's probably your program's fault.
==4971== 2. The instruction is legitimate but Valgrind doesn't handle it,
==4971==    i.e. it's Valgrind's fault.  If you think this is the case or
==4971==    you are not sure, please let us know and we'll try to fix it.
==4971== Either way, Valgrind will now raise a SIGILL signal which will
==4971== probably kill your program.
==4971== 
==4971== Process terminating with default action of signal 4 (SIGILL)
==4971==  Illegal opcode at address 0x48426F4
==4971==    at 0x48426F4: ??? (in /usr/lib/arm-linux-gnueabihf/libarmmem.so)
==4971== 
==4971== HEAP SUMMARY:
==4971==     in use at exit: 1,479,613 bytes in 219 blocks
==4971==   total heap usage: 5,067 allocs, 4,848 frees, 1,862,262 bytes allocated
==4971== 
==4971== 144 bytes in 1 blocks are possibly lost in loss record 37 of 52
==4971==    at 0x4835770: calloc (vg_replace_malloc.c:566)
==4971==    by 0x401283B: allocate_dtv (dl-tls.c:296)
==4971==    by 0x4012F0F: _dl_allocate_tls (dl-tls.c:460)
==4971==    by 0x4A76C93: pthread_create@@GLIBC_2.4 (allocatestack.c:589)
==4971==    by 0x164C9B: sthread_create (rthreads.c:146)
==4971==    by 0x3A057: retro_task_threaded_init (task_queue.c:497)
==4971==    by 0x3A29F: task_queue_ctl (task_queue.c:571)
==4971==    by 0x3714B: runloop_ctl (runloop.c:561)
==4971==    by 0x1F68F: retroarch_main_init (retroarch.c:1041)
==4971==    by 0x3B00F: content_load (task_content.c:275)
==4971==    by 0x3C57F: task_load_content (task_content.c:817)
==4971==    by 0x3CFF3: task_push_content_load_default (task_content.c:1235)
==4971== 
==4971== 67,584 bytes in 1 blocks are definitely lost in loss record 50 of 52
==4971==    at 0x4833970: malloc (vg_replace_malloc.c:263)
==4971==    by 0x5D36FB3: FCEU_malloc (fceu-memory.c:44)
==4971==    by 0x5D4FDA3: FCEU_InitVirtualVideo (video.c:51)
==4971==    by 0x5D37E6F: FCEUI_Initialize (fceu.c:340)
==4971==    by 0x5D30C2B: retro_load_game (libretro.c:1544)
==4971==    by 0x1CEEB: core_load_game (core_impl.c:289)
==4971==    by 0x3BB9B: content_file_load (task_content.c:562)
==4971==    by 0x3C2B7: content_file_init (task_content.c:746)
==4971==    by 0x3D507: content_init (task_content.c:1416)
==4971==    by 0x25E77: event_init_content (command.c:1330)
==4971==    by 0x26047: command_event_init_core (command.c:1395)
==4971==    by 0x27ABB: command_event (command.c:2219)
==4971== 
==4971== LEAK SUMMARY:
==4971==    definitely lost: 67,584 bytes in 1 blocks
==4971==    indirectly lost: 0 bytes in 0 blocks
==4971==      possibly lost: 144 bytes in 1 blocks
==4971==    still reachable: 1,411,885 bytes in 217 blocks
==4971==         suppressed: 0 bytes in 0 blocks
==4971== Reachable blocks (those to which a pointer was found) are not shown.
==4971== To see them, rerun with: --leak-check=full --show-reachable=yes
==4971== 
==4971== For counts of detected and suppressed errors, rerun with: -v
==4971== Use --track-origins=yes to see where uninitialised values come from
==4971== ERROR SUMMARY: 4108 errors from 14 contexts (suppressed: 0 from 0)
Killed

@ghost
Copy link

ghost commented Jan 2, 2017

It looks like valgrind may be tripping on itself, it is dying with a completely different issue somewhere in ARM land. Can you try running under AddressSanitizer instead? Just make clean && make -j DEBUG=1 SANITIZER=address then run RA as usual.

@inactive123
Copy link
Contributor

See if this fixes anything -

libretro/libretro-fceumm@768fa48

@joolswills
Copy link
Contributor

@bparker06 I suspected it wasn't that useful. Unfortunately SANITIZER=address doesn't seem to be much helper either :/

./retroarch -L ../libretro-fceumm/fceumm_libretro.so --config /opt/retropie/configs/nes/retroarch.cfg "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].zip" --verbose
RetroArch [INFO] :: Redirecting save file to "/home/pi/RetroPie/roms/nes/Super Mario Bros. (JU) [!].srm".
RetroArch [INFO] :: === Build =======================================
Capabilities: NEON VFPv3 VFPv4 
Built: Jan  2 2017
RetroArch [INFO] :: Version: 1.3.6
RetroArch [INFO] :: Git: f95759c
RetroArch [INFO] :: =================================================
RetroArch [INFO] :: Config: loading config from: /opt/retropie/configs/nes/retroarch.cfg.
RetroArch [INFO] :: Incompatible shader for backend gl, clearing...
ASAN:SIGSEGV
=================================================================
==13167==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000 (pc 0x00000000 sp 0x7e81f6f0 bp 0x7e81f714 T0)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ??:0 ??
==13167==ABORTING

@twinaphex unfortunately not. do you want another backtrace after this libretro-fceumm change ?

@inactive123
Copy link
Contributor

inactive123 commented Jan 2, 2017

You could try giving me another backtrace, but I'm not sure if I can be of help.

I think you should maybe try finding a fix for this yourself, we don't have your hardware. You know how to debug so you should be able to go from there.

@joolswills
Copy link
Contributor

I may well - but best to start by feeding the information to you first no ? Also - I have limited free time along with my own projects etc.

@inactive123
Copy link
Contributor

Fine, provide your other backtrace then, so far though I don't really see what the problem could be and you actually have the hardware and the ability to debug it.

@inactive123
Copy link
Contributor

@joolswills This is from your pastebin -

*** Error in `/opt/retropie/emulators/retroarch/bin/retroarch': free(): invalid pointer: 0x01ff8979 ***

Can you find out which free function call this is happening on inside the RA codebase?

@joolswills
Copy link
Contributor

joolswills commented Jan 2, 2017

I believe src/video.c in libretro_fceum line 43 (see bt)

 void FCEU_KillVirtualVideo(void)
 {
       if (XBuf)
               free(XBuf);
   XBuf = 0;

Although XBuf should only be freed if not NULL (and should be a valid pointer)

@joolswills
Copy link
Contributor

The crash seems to go if I comment out this piece of code in src/video.c - some sort of alignment code ?

   if (sizeof(uint8*) == 4)
   {
      uintptr_t m;
      m = (uintptr_t)*XBuf;
      m = (4 - m) & 3;
      XBuf += m;
   }

@inactive123
Copy link
Contributor

yeah looks like a real mess. The nasty surprises just never end with some of these codebases

@joolswills
Copy link
Contributor

Looks wrong anyway - because you can't free(XBuf) after incrementing it. If it's trying to allocate some aligned memory there must be a better way.

@ghost
Copy link

ghost commented Jan 2, 2017

@joolswills Perhaps XBuf was null at that point?

@joolswills
Copy link
Contributor

@bparker06 It wasn't null as the free got called - it had been allocated, but then incremented - see the above for the faulty code.

@ghost
Copy link

ghost commented Jan 2, 2017

I meant, at the point XBuf is incremented, is it null?

@joolswills
Copy link
Contributor

I don't think so as it wouldn't get that far. The code needs to save the original malloc address for the free and it should fix it (if the alignment code is needed for performance).

@joolswills
Copy link
Contributor

joolswills commented Jan 2, 2017

eg (very rough - but it stops the crash).

diff --git a/src/video.c b/src/video.c
index 5db5b86..a622f1a 100644
--- a/src/video.c
+++ b/src/video.c
@@ -35,24 +35,27 @@
 #include "input.h"
 #include "vsuni.h"
 
-uint8 *XBuf = NULL;
+uint8 *XBuf;
+static uint8 *XBuf_orig = NULL;
 
 void FCEU_KillVirtualVideo(void)
 {
-       if (XBuf)
-               free(XBuf);
-   XBuf = 0;
+       if (XBuf_orig)
+               free(XBuf_orig);
+   XBuf_orig = 0;
 }
 
 int FCEU_InitVirtualVideo(void)
 {
    // 256 bytes per scanline, * 240 scanline maximum, +8 for alignment,
-   if (!XBuf)
-      XBuf = (uint8*)(FCEU_malloc(256 * (256 + extrascanlines + 8)));
+   if (!XBuf_orig)
+      XBuf_orig = (uint8*)(FCEU_malloc(256 * (256 + extrascanlines + 8)));
 
-   if (!XBuf)
+   if (!XBuf_orig)
       return 0;
 
+   XBuf = XBuf_orig;
+
    if (sizeof(uint8*) == 4)
    {
       uintptr_t m;

@inactive123
Copy link
Contributor

Try seeing if this fixes it -

libretro/libretro-fceumm@d85ca94

@joolswills
Copy link
Contributor

joolswills commented Jan 2, 2017

That works thanks, but it might be worth keeping the alignment code as it could have performance benefits ? (as with my example - saving the original pointer for use with free) but up to you.

@ghost
Copy link

ghost commented Jan 2, 2017

The malloc'ed memory would already be aligned so I think it's unnecessary.

@joolswills
Copy link
Contributor

joolswills commented Jan 2, 2017

sounds good then. the only other thing is the change removes the check to see if the memory allocated ok which probably should be kept (and the check to not allocate if already allocated - are we 100% sure this doesn't ever get called again without calling FCEU_KillVirtualVideo ?)

@inactive123
Copy link
Contributor

I put that check back already.

@joolswills
Copy link
Contributor

ok great. so all good :)

@ghost
Copy link

ghost commented Jan 2, 2017

:feelsgood:
Gotta love when people can't code for shit.

@inactive123
Copy link
Contributor

@bmn001 Let me know if this fix doesn't work for you, you need to update your copy of FCEUmm.

@bmn001
Copy link
Author

bmn001 commented Jan 3, 2017

Just wanted to chime in to confirm that yes, this update did indeed fix the problem I was seeing.

Thank you so much to @twinaphex @joolswills @bparker06 and everyone else who helped for taking the report seriously and really digging in to discover what appeared to be a pretty obscure issue. I (and probably hundreds of silent other sufferers) will benefit from your work and we absolutely appreciate the effort. Thank you.

@joolswills
Copy link
Contributor

joolswills commented Feb 5, 2017

Just to note - the alignment code actually makes quite a noticeable difference in performance when testing on armv6 (rpi1). On RPI1 on Super Mario without overclocking it's 45fps without and 50fps with. Still not fullspeed, but with the alignment code a small overclock is enough for fullspeed.

I am going to put it back into retropie - (Obviously a working version so we free the correct pointer) - @twinaphex would you accept a working patch that includes the alignment code?

Note that although @bparker06 said malloc already aligns - I guess it isn't optimal for the best performance in this case. (4 bytes aligned).

@joolswills
Copy link
Contributor

Sorry I actually need to do more testing - I'm now not sure this code makes any difference so perhaps malloc aligns to 4 bytes anyway. It must be something else causing the performance difference I have seen - will do more testing. Sorry for the spam.

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

No branches or pull requests

8 participants