libretro / flycast

Flycast is a multiplatform Sega Dreamcast emulator. NOTE: No longer actively developed, use upstream repo for libretro from now on - https://github.com/flyinghead/flycast
http://reicast.com
GNU General Public License v2.0
155 stars 78 forks source link

using CHDs v5 results in a Illegal instruction/bus error #712

Open shantigilbert opened 5 years ago

shantigilbert commented 5 years ago

I compile flycast from source and V5 CHDs seem to not be working, I saw an old issue that claims they do work, but everytime I load a v5 it crashes

I have 3 versions of the same game in CHD, 2 are v5 and one is v4, v4 loads and plays fine, but v5 does not, this is the info for the CHDs:

V5, does not work:

chdman - MAME Compressed Hunks of Data (CHD) manager 0.195 (unknown)
Input file:   gdl-0010.chd
File Version: 5
Logical size: 1,344,333,888 bytes
Hunk Size:    19,584 bytes
Total Hunks:  68,645
Unit Size:    2,448 bytes
Total Units:  549,156
Compression:  lzma (LZMA), zlib (Deflate), huff (Huffman), flac (FLAC)
CHD size:     63,063,799 bytes
Ratio:        4.7%
SHA1:         cdae4618adfd8eab5a06fbb491ce18a0286e3cae
Data SHA1:    22f8c580b7032b4f9245eb0f3af2ca73f9ff6a4f
Metadata:     Tag='CHGT'  Index=0  Length=97 bytes
              TRACK:1 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:9833 PAD:150 PREG
Metadata:     Tag='CHGT'  Index=1  Length=96 bytes
              TRACK:2 TYPE:AUDIO SUBTYPE:NONE FRAMES:35167 PAD:33034 PREGA
Metadata:     Tag='CHGT'  Index=2  Length=97 bytes
              TRACK:3 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:504150 PAD:0 PREG

Crashes with

libretro INFO] 00:00:717 hw/mem/_vmem.cpp:547 N[VMEM]: Info: nvmem is enabled, with addr space of size 512MB
[libretro ERROR] 00:00:851 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ f01bb540 ... (nil) -> was not in vram (dyna code 0)
[libretro INFO] Fatal error : segfault
 in signal_handler -> core/libretro/common.cpp : 374 

[libretro ERROR] 00:00:851 libretro/libretro.cpp:3084 E[COMMON]: DEBUGBREAK!
[libretro ERROR] 00:00:851 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ f01beb48 ... 0xf01beb48 -> was not in vram (dyna code 0)
[libretro INFO] Fatal error : segfault
 in signal_handler -> core/libretro/common.cpp : 374 

[libretro ERROR] 00:00:851 libretro/libretro.cpp:3084 E[COMMON]: DEBUGBREAK!
Illegal instruction

V5 does not work:

chdman - MAME Compressed Hunks of Data (CHD) manager 0.195 (unknown)
Input file:   gdl-0010.chd
File Version: 5
Logical size: 1,344,333,888 bytes
Hunk Size:    19,584 bytes
Total Hunks:  68,645
Unit Size:    2,448 bytes
Total Units:  549,156
Compression:  cdlz (CD LZMA), cdzl (CD Deflate), cdfl (CD FLAC)
CHD size:     34,167,090 bytes
Ratio:        2.5%
SHA1:         58a592ba217847808940608548a1bfdf0ae9e713
Data SHA1:    c18cf874c5b913c031ff0da0eb5ec6ac96f6a86a
Metadata:     Tag='CHGD'  Index=0  Length=99 bytes
              TRACK:1 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:9833 PAD:150 PREG
Metadata:     Tag='CHGD'  Index=1  Length=98 bytes
              TRACK:2 TYPE:AUDIO SUBTYPE:NONE FRAMES:35167 PAD:33034 PREGA
Metadata:     Tag='CHGD'  Index=2  Length=99 bytes
              TRACK:3 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:504150 PAD:0 PREG

Crashes with

Bus error

V4, works fine

Input file:   gdl-0010.chd
File Version: 4
Logical size: 1,344,333,888 bytes
Hunk Size:    9,792 bytes
Total Hunks:  137,289
Unit Size:    2,448 bytes
Total Units:  549,156
Compression:  zlib (Deflate)
CHD size:     80,785,378 bytes
Ratio:        6.0%
SHA1:         65dcc22dd9e9b70975096464ad8e31a4a73dc5fd
Data SHA1:    3b853be7208f523100690e12a661173d023af9c1
Metadata:     Tag='CHTR'  Index=0  Length=48 bytes
              TRACK:1 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:9683.
Metadata:     Tag='CHTR'  Index=1  Length=45 bytes
              TRACK:2 TYPE:AUDIO SUBTYPE:NONE FRAMES:35317.
Metadata:     Tag='CHTR'  Index=2  Length=50 bytes
              TRACK:3 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:504150.

I compile with

HAVE_OPENMP=0 WITH_DYNAREC=arm ARCH=arm platform=AMLG12B

Amlogic Odroid N2 using Emuelec on ARM 32bit user space

barolo commented 5 years ago

I have all my games compressed freshly with newest chdman [ 0.215 ] and none of them crash flycast

Darknior commented 5 years ago

For my part CHD 5 never works on Flycast, i must always use v4 from a long time ... i havve try with version 205, i don't have the 215 ??? And i'm not sure it change something ?

barolo commented 5 years ago

It's the only format that I'm using and its chd5 with very recent flycast build [ compiled from master ], you can get one from the buildbot to test it https://buildbot.libretro.com/nightly/

chdman - MAME Compressed Hunks of Data (CHD) manager 0.215 (unknown)
Input file:   De La Jet Set Radio (Japan) (En,Ja,Fr,De,Es).chd
File Version: 5
Logical size: 1,344,333,888 bytes
Hunk Size:    19,584 bytes
Total Hunks:  68,645
Unit Size:    2,448 bytes
Total Units:  549,156
Compression:  cdlz (CD LZMA), cdzl (CD Deflate), cdfl (CD FLAC)
CHD size:     662,321,225 bytes
Ratio:        49.3%
SHA1:         465686c83183542f8c11115149005cc30d670f97
Data SHA1:    78e68a3ad45b17c1c9cd9fd066c10b9b36520b06
Metadata:     Tag='CHGD'  Index=0  Length=96 bytes
              TRACK:1 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:450 PAD:0 PREGAP:
Metadata:     Tag='CHGD'  Index=1  Length=98 bytes
              TRACK:2 TYPE:AUDIO SUBTYPE:NONE FRAMES:44550 PAD:43662 PREGA
Metadata:     Tag='CHGD'  Index=2  Length=99 bytes
              TRACK:3 TYPE:MODE1_RAW SUBTYPE:NONE FRAMES:504150 PAD:0 PREG
barolo commented 5 years ago

It might be related to the platform you use? This is on arm board. There is not even an arm version on the buildbot, I am testing a version I compile myself, with latest commits.

That's possible, I'm on Linux x86_64. It seems related to LZMA compression, as that's what is used in v5 but not v4. I've seen some bugs floating around with it on ARM. Most likely not a flycast bug

Darknior commented 5 years ago

CHD have some bugs for sure ... on Saturn i found one, All the translated games are not working fine on CHD 5 ou 4 format with YaSanshiro and Kronos !! But working fine in ISO format :( So strange because all original games are working fine in CHD format. But there is a solution for this because !!! so strange !!! All trad games working fine in CHD format with Beetle Saturn ??!! why ?? Maybe something in his source code ?? But some one must search for this and found where is the solution.

flyinghead commented 5 years ago

I use CHD v5 pretty much exclusively and on all platforms. I just tested a bunch of them on arm32 and they all load fine. Can you share which games you have issue with?

Darknior commented 5 years ago

@flyinghead you speak about Dreamcast games ? Not Saturn like i write ? And i try Saturn games on my PC Windows 10 Intel I5 3.4 Ghz, not on ARM device. It's why i'm sure what i write ... and i try V4 V5 there are some strange things on some games with CHD, on Saturn it's only with translated games and really o don't found why because the ISO working fine ...

barbudreadmon commented 5 years ago

@Darknior this is the flycast repo, please don't hijack this issue to report about non-flycast issues...

DJoneK commented 5 years ago

CHDv5 works on my end. If you are using a .cue to create the .chd, it WILL NOT load though. For some reason, you NEED to use a .gdi to create the .chd files. If you have redump matching images, you can still download the .gdi needed from their Download section.

I'm guessing it's something to do with the extra gap info that .cue has compared to .gdi and some offset difference it's messing with loading data. Dunno. I'm just using logic. No idea what may be going on though.

flyinghead commented 5 years ago

I converted my Ikaruga GDI to CHD using different chdman versions (0.195, 0.202, 0.214, 0.215) and they all load fine. Can you get a stacktrace with a debug build of when it crashes?

flyinghead commented 5 years ago

You can use the regular non-debug retroarch.

gdb --args retroarch -v -L flycast_libretro.so ikaruga.chd
r

and when it crashes: bt

flyinghead commented 5 years ago

A debug build will probably be too slow to be usable. Please build a release version but with the -g option in CFLAGS so we get debug symbols at least. Then retry with gdb.

flyinghead commented 5 years ago

Next time you open an issue, give ALL useful details. Why don't you say you're using the NAOMI ikaruga and not the dreamcast one? This is completely different and that way I don't waste my time looking for non-existent problems...

shantigilbert commented 5 years ago

Ok...Sorry for wasting your time!

flyinghead commented 4 years ago

I've had reports of apparently the same issue on Lakka on Rpi4. I have tried to reproduce it on android 32-bit and RPi3 without success.

It seems to happen only on ARM32 and for CHD v5 Naomi games. Also it doesn't seem to happen on Android (gcc? glibc?)

shantigilbert commented 4 years ago

The workaround I used was to force using -O2 as optimization

--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@
 HAVE_CLANG    ?= 0
 HAVE_CDROM    := 0
 THREADED_RENDERING_DEFAULT := 0
+SET_OPTIM     := -O2

 TARGET_NAME   := flycast
@@ -889,7 +890,7 @@
    ifneq (,$(findstring msvc,$(platform)))
        OPTFLAGS       := -O2
    else ifneq ($(platform), classic_armv7_a7)
-       OPTFLAGS       := -O3
+       OPTFLAGS       := $(SET_OPTIM)
    endif

    CORE_DEFINES   += -DNDEBUG

As I noticed if I compiled the debug version it worked fine. Not sure this will fix other platforms tho.

flyinghead commented 4 years ago

Thank you for the information. What version of gcc are you using?

shantigilbert commented 4 years ago

8.3.0

flyinghead commented 4 years ago

I cross-compiled using gcc 8.3 and still cannot get a crash on the rpi3.