adventuregamestudio / ags

AGS editor and engine source code
Other
676 stars 159 forks source link

Spaceship/Starship Quasar new problems #1116

Closed i30817 closed 3 years ago

i30817 commented 3 years ago

Describe the bug

Two new problems in Quasar, one of sound, which appears 'somehow' to be occuring even on ancient compiles so i don't know what's up with that (corrupted crackly sound maybe a slight 'fast forward', maybe a pulseaudio problem).

The other a crash after pressing play in the main menu with a normal compile (debug compile doesn't crash but the speech audio just zips forward).

In the cmd line: WARNING: channel 2 - same clip assigned. And sometimes corrupted double-linked list (not small).

The non-debug gdb backtrace:

GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /media/i30817/Huginn/Documents/projects/ags/Engine/ags...
(gdb) r
Starting program: /media/i30817/Huginn/Documents/projects/ags/Engine/ags 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Adventure Game Studio v3.5 Interpreter
Copyright (c) 1999-2011 Chris Jones and 2011-2020 others
ACI version 3.5.0.25

Initializing allegro
[New Thread 0x7ffff6e01700 (LWP 36363)]
Initializing game data
Located game data file: /media/i30817/Ags/Spaceship Quasar/Quasar.exe
Opened game data file: game28.dta
Game data version: 43
Compiled with: 3.3.0.1162
Setting up game configuration
Data directory: /media/i30817/Ags/Spaceship Quasar/
Voice pack found and initialized.
audio.vox found and initialized.
Setting up window
Initializing TTF renderer
Initializing keyboard
Initializing mouse: number of buttons reported is 3
Install timer
Sound settings: digital driver ID: 'AUTO' (0xffffffff), MIDI driver ID: 'NONE' (0x0)
[New Thread 0x7ffff58e8700 (LWP 36364)]
Trying to init: digital driver ID: 'ALSA' (0x414c5341), MIDI driver ID: 'NONE' (0x0)
[New Thread 0x7ffff58e8700 (LWP 36365)]
[Thread 0x7ffff58e8700 (LWP 36364) exited]
[Thread 0x7ffff58e8700 (LWP 36365) exited]
[New Thread 0x7ffff58e8700 (LWP 36366)]
[New Thread 0x7ffff50e7700 (LWP 36367)]
Installed digital driver ID: 'ALSA' (0x414c5341), MIDI driver ID: 'NONE' (0x0)
Install exit handler
Initialize legacy path finder library
Game GUI version: 116
Game title: 'Quasar'
Checking for disk space
Initializing MOD/XM player
Game native resolution: 640 x 400 (32 bit)
Graphic settings: driver: OGL, windowed: no, screen def: max, screen size: 0 x 0, match device ratio: yes, game scale: proportional
[New Thread 0x7fffc22ed700 (LWP 36368)]
[New Thread 0x7fffc1aec700 (LWP 36369)]
[New Thread 0x7fffc12eb700 (LWP 36370)]
[New Thread 0x7fffc0aea700 (LWP 36371)]
[New Thread 0x7fffb3fff700 (LWP 36372)]
Running OpenGL: 3.0
Mouse control: on, base: 1.000000, speed: 2.000000
Initialize sprites
Audio is processed on the main thread
Engine initialization complete
Starting game
WARNING: channel 2 - same clip assigned
corrupted double-linked list (not small)

Thread 1 "ags" received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff778a859 in __GI_abort () at abort.c:79
#2  0x00007ffff77f53ee in __libc_message (action=action@entry=do_abort, 
    fmt=fmt@entry=0x7ffff791f285 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#3  0x00007ffff77fd47c in malloc_printerr (
    str=str@entry=0x7ffff7921248 "corrupted double-linked list (not small)")
    at malloc.c:5347
#4  0x00007ffff77fdaf7 in unlink_chunk (p=p@entry=0x555557211f60, 
    av=0x7ffff7950b80 <main_arena>) at malloc.c:1468
#5  0x00007ffff77ff00b in _int_free (av=0x7ffff7950b80 <main_arena>, 
    p=0x55555720ff50, have_lock=<optimized out>) at malloc.c:4342
#6  0x00005555558113f0 in __gnu_cxx::new_allocator<char>::deallocate (
    this=0x555557214b38, __p=<optimized out>)
    at /usr/include/c++/9/ext/new_allocator.h:119
#7  std::allocator_traits<std::allocator<char> >::deallocate (__a=..., 
    __n=<optimized out>, __p=<optimized out>)
    at /usr/include/c++/9/bits/alloc_traits.h:470
#8  std::_Vector_base<char, std::allocator<char> >::_M_deallocate (
    this=0x555557214b38, __n=<optimized out>, __p=<optimized out>)
    at /usr/include/c++/9/bits/stl_vector.h:351
#9  std::_Vector_base<char, std::allocator<char> >::~_Vector_base (
    this=0x555557214b38, __in_chrg=<optimized out>)
    at /usr/include/c++/9/bits/stl_vector.h:332
--Type <RET> for more, q to quit, c to continue without paging-- c
#10 std::vector<char, std::allocator<char> >::~vector (this=0x555557214b38, __in_chrg=<optimized out>) at /usr/include/c++/9/bits/stl_vector.h:680
#11 AGS::Common::BufferedStream::~BufferedStream (this=0x555557214b10, __in_chrg=<optimized out>) at ../Common/util/bufferedstream.h:33
#12 AGS::Common::BufferedStream::~BufferedStream (this=0x555557214b10, __in_chrg=<optimized out>) at ../Common/util/bufferedstream.h:33
#13 0x00005555556d8f13 in ags_pf_fclose (userdata=<optimized out>) at ac/file.cpp:404
#14 0x00007ffff7ec63cd in pack_fclose () from /lib/x86_64-linux-gnu/liballeg.so.4.4
#15 0x0000555555778ccc in get_cached_sound (asset_name={...}, is_wave=is_wave@entry=true, size=size@entry=0x7fffffffcb10) at media/audio/soundcache.cpp:136
#16 0x00005555557781a0 in my_load_wave (asset_name={...}, voll=100, loop=loop@entry=0) at media/audio/sound.cpp:68
#17 0x000055555577a5a8 in load_sound_clip (audioClip=0x555555d51430, repeat=<optimized out>) at media/audio/audio.cpp:266
#18 0x000055555577b36f in load_sound_and_play (aclip=aclip@entry=0x555555d51430, repeat=repeat@entry=false) at media/audio/audio.cpp:702
#19 0x0000555555735eab in PlaySoundEx (val1=val1@entry=5, channel=3) at ac/global_audio.cpp:147
#20 0x000055555577b49b in play_sound_priority (priority=10, val1=5) at media/audio/audio.cpp:755
#21 play_sound (val1=5) at media/audio/audio.cpp:791
#22 0x0000555555700551 in Sc_play_sound (params=<optimized out>, param_count=<optimized out>) at ../Engine/script/runtimescriptvalue.h:62
#23 0x000055555578d508 in ccInstance::Run (this=this@entry=0x555555f3b150, curpc=curpc@entry=8709) at script/cc_instance.cpp:1098
#24 0x000055555578d8ca in ccInstance::CallScriptFunction (this=0x555555f3b150, funcname=<optimized out>, numargs=numargs@entry=2, params=params@entry=0x7fffffffd360) at script/cc_instance.cpp:368
#25 0x0000555555785b6a in RunScriptFunctionIfExists (sci=sci@entry=0x555555f3b150, tsname=<optimized out>, tsname@entry=0x55555582caa7 "interface_click", numParam=numParam@entry=2, params=params@entry=0x7fffffffd360) at script/script.cpp:407
#26 0x0000555555785f4d in RunTextScript2IParam (sci=0x555555f3b150, tsname=<optimized out>, iparam=..., param2=...) at script/script.cpp:494
#27 0x0000555555785feb in RunScriptFunction (sc_inst=<optimized out>, fn_name=<optimized out>, param_count=<optimized out>, p1=..., p2=...) at script/script.cpp:305
#28 0x000055555578602d in QueueScriptFunction (sc_inst=sc_inst@entry=kScInstGame, fn_name=fn_name@entry=0x55555582caa7 "interface_click", param_count=param_count@entry=2, p1=..., p2=...) at script/script.cpp:296
#29 0x000055555572c322 in process_interface_click (ifce=4, btn=0, mbut=1) at ../Engine/script/runtimescriptvalue.h:161
#30 0x00005555556b1c56 in process_event (evp=0x7fffffffd97c) at ac/event.cpp:372
#31 0x00005555556b2739 in processallevents (numev=<optimized out>, evlist=evlist@entry=0x555555bd7640 <event>) at ac/event.cpp:405
#32 0x00005555556b27d6 in processallevents (evlist=0x555555bd7640 <event>, numev=<optimized out>) at ac/event.cpp:416
#33 update_events () at ac/event.cpp:415
#34 0x000055555576ffa5 in game_loop_update_events () at main/game_run.cpp:687
#35 UpdateGameOnce (extraY=<optimized out>, extraX=<optimized out>, extraBitmap=<optimized out>, checkControls=<optimized out>) at main/game_run.cpp:814
#36 UpdateGameOnce (checkControls=<optimized out>, extraBitmap=<optimized out>, extraX=<optimized out>, extraY=<optimized out>) at main/game_run.cpp:758
#37 0x0000555555770a65 in GameTick () at main/game_run.cpp:940
#38 0x0000555555770cf5 in RunGameUntilAborted () at main/game_run.cpp:1035
#39 0x0000555555770fa9 in initialize_start_and_play_game (override_start_room=0, loadSaveGameOnStartup=<optimized out>) at main/game_start.cpp:153
#40 0x000055555576a02c in initialize_engine (startup_opts=Python Exception <class 'AttributeError'> 'NoneType' object has no attribute 'pointer': 
std::map with 0 elements) at main/engine.cpp:1582
#41 0x00005555557761ef in ags_entry_point (argc=1, argv=0x7fffffffdee8) at main/main.cpp:483
#42 0x00007ffff778c0b3 in __libc_start_main (main=0x55555563be10 <main(int, char**)>, argc=1, argv=0x7fffffffdee8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffded8) at ../csu/libc-start.c:308
#43 0x000055555563e3be in _start () at /usr/include/c++/9/bits/shared_ptr_base.h:1169

AGS Version d8810107d83241dc2d6594a5283a15cc709f118f (current master)

Game Starship/Spaceship Quasar, often called 'Quasar' only.

To Reproduce

  1. start game
  2. choose english
  3. click play

Desktop (please complete the following information):

Additional context Since this was working when the last 'lip sync problem' https://github.com/adventuregamestudio/ags/issues/761 i also reported was fixed in 870d5d8, i'm doing a bisect, and found that the 'corrupted audio' was already happening then ( but i don't remember it) so i'll probably investigate config alterations for that later, maybe it's pulseaudio. Meanwhile, i bisected the crash.

a1329085d94e3723e4cbb960a8b1818c1d9a00dc is the first broken commit
commit a1329085d94e3723e4cbb960a8b1818c1d9a00dc
Author: Ivan Mogilko <ikm_spb@yahoo.com>
Date:   Sun Jul 26 21:06:17 2020 +0300

    Engine: use custom PACKFILE which wraps our Stream for 64-bit file size

 Engine/ac/file.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 73 insertions(+), 11 deletions(-)

I'll note that this is 'just' the first commit where the game started quitting on me, not the first where the sound is corrupted (i couldn't find it, may be something in the system), or the final result of a segfault - instead, this early it appears to result in a random (I saw 2 and 11) allegro signal and shutdown.

i30817 commented 3 years ago

Anyway i think this is because i upgraded gcc and got a new linked list anti-memory corruption check as a extra. The bug may have existed for a while and only crash on the new gcc.

i30817 commented 3 years ago

BTW quest for infamy presents a probably related problem in the 'cart intro' where the very fist dialog 'doesn't stop' at the line that is said and other lines of the npc are said after the line finishes. It appears that the end offset of the voice clips is very very wrong in the 64 packfile parser for the old 32 bit games.

No corrupted 'too fast' sound though.

i30817 commented 3 years ago

The crash seems random but i can confirm that both quasar and qfi voice clips no longer stop if you don't click the mouse after (including) that commit. Quasar sound worked fine this time, so i don't even know what's up with that, but on this test QFI crashed with the Allegro signal 11, so... random (at least that early on the bug).

ivan-mogilko commented 3 years ago

Ah. I missed a comment in Allegro headers, and apparently one thing I am doing in a1329085d94e3723e4cbb960a8b1818c1d9a00dc is forbidden. There's a segment of PACKFILE struct that is not even allocated in memory if custom vtable is assigned. Engine uses one field from that segment to know the sound length. That definitely explains why sounds are longer, and most probably can lead to crashes, as engine writes (once) and reads (multiple times) in either another location or unallocated memory.

I will have to figure out how to pass sound size instead of using this field. If that's not possible because of how 3rd party libraries like aldumb work, then maybe I could just allocate PACKFILE myself the way I need. Looking at allegro code, there's nothing complicated there.

PS. Regarding sound noises, can't tell for sure, but that has been a problem for number of users (me included) for years. Potential solution is to switch to our custom SDL2 audio driver, for which you'd need alleg-sdl2digi.so library. One may be acquired from prebuilt linux binaries attached to any recent release, or built from our allegro branch: https://github.com/adventuregamestudio/lib-allegro/blob/allegro-4.4.3.1-agspatch/src/unix/sdl2digi.c

i30817 commented 3 years ago

Huh. Thanks for the information, i'll try the driver later.

ivan-mogilko commented 3 years ago

@i30817 pushed commit ca5cf89b8c2252097e095a0e74a06be87819de6a please tell if it improved anything.

i30817 commented 3 years ago

Right seems to work, except the 'speed up digital sound' which is the other problem.

i30817 commented 3 years ago

How do you build that .so? Preferably as a static library. Doesn't seem to have a make file component in ags, and i just cloned lib-allegro and i'm unsure of how to hook it up to ags either. Can i just dump the so file in the same dir as the ags file if i manage to build it?

ivan-mogilko commented 3 years ago

It's not a direct component of ags, but should be hooked up by allegro as a plugin if there's also modules.lst text file with this so name in a directory where allegro can look for libraries. The example of this may be found in prebuilt linux binary archive. As for building, frankly this is something I did not try to do myself yet. In theory it may be built when you are building allegro with certain flags. I have to investigate this again first to have any answers.

i30817 commented 3 years ago

I built allegro right now (it's a cmake thing so i could use cmake-qt-gui), and it appears that that file is inbuilt/included as a .o file not a .so. So i'm kind of suspecting i have to link in the whole allegro 4. dll/so into ags and not depend on the system one.

I suppose i could try a prebuilt one, if i can find a prebuilt linux x86-64 binary somewhere. The Cirrus CI only appears to link to statically linked single ags files though.

ivan-mogilko commented 3 years ago

This "linux packaging" task on CI should contain all necessary prebuilt libraries for recent master branch: https://cirrus-ci.com/task/6155898517192704

i30817 commented 3 years ago

This is too complicated to me. Meanwhile i rebooted and the too fast sound in the alsa driver (running with pulse which may influence things) magically fixed itself. I hate it but i'm going to ignore this error. If you want solve it, i'll be on the lookout for a way to force it happening but i can't guarantee anything.