yuv422 / cosmo-engine

A new game engine to play the MS-DOS game "Cosmo's Cosmic Adventure" on modern systems
GNU General Public License v2.0
58 stars 12 forks source link

Segfault in bonus level #9

Closed jschwartzenberg closed 4 years ago

jschwartzenberg commented 4 years ago

To reproduce, collect 55 stars. Enter the bonus level where you can jump from trampoline to trampoline from left to right until the most right side of the screen. Then drop down and do not go in any exit but keep walking around and collecting items that are on the bottom and touching the green creatures.

I ran into a segfault there twice now. Here is what I get in GDB:

$ gdb ./cosmo_engine 
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 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 ./cosmo_engine...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/julius/checkouts/cosmo-engine/build/cosmo_engine 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffeac70700 (LWP 20755)]
[New Thread 0x7ffff7f93700 (LWP 20756)]
[New Thread 0x7fffea46f700 (LWP 20757)]
audio_init(): opened=1 times  frequency=22050Hz  format=S16LSB  channels=1
Failed opening './COSMO1.CFG'
Loading 228 status tiles.
Loading 750 player tiles.
Loading 1, player tile info records.
Loaded 4797 actor tiles.
Loading 267, actor tile info records.
Loading 2000 map bg tiles.
Loading 1000 map fg tiles.
Loading 1607 cartoon tiles.
Loading 1, cartoon tile info records.
Loading 100 font tiles.
Total Sfx 72
SOUNDS.MNI, 24, 0
SOUNDS2.MNI, 24, 23
SOUNDS3.MNI, 24, 46
Level 0: rain=0, backdrop_index=11, bg_x_scroll=64, bg_y_scroll=0, pal_anim_type=0, music_index=8
Loading 720 background tiles.
map width (in tiles): 512
Level 1: rain=0, backdrop_index=11, bg_x_scroll=64, bg_y_scroll=0, pal_anim_type=0, music_index=8
map width (in tiles): 512
Failed opening './COSMO1.SV1'
Failed opening './COSMO1.SV2'
Failed opening './COSMO1.SV3'
Failed opening './COSMO1.SV4'
Failed opening './COSMO1.SV5'
Failed opening './COSMO1.SV6'
Failed opening './COSMO1.SV7'
Failed opening './COSMO1.SV8'
Failed opening './COSMO1.SV9'
Failed opening './COSMO1.SV2'
Failed opening './COSMO1.SV3'
Failed opening './COSMO1.SV4'
Failed opening './COSMO1.SV5'
Failed opening './COSMO1.SV6'
Failed opening './COSMO1.SV7'
Failed opening './COSMO1.SV8'
Failed opening './COSMO1.SV9'
Level 3: rain=0, backdrop_index=13, bg_x_scroll=64, bg_y_scroll=128, pal_anim_type=0, music_index=10
Loading 720 background tiles.
map width (in tiles): 512

Thread 1 "cosmo_engine" received signal SIGSEGV, Segmentation fault.
0x000055555555f367 in map_get_tile_cell ()
(gdb) bt
#0  0x000055555555f367 in map_get_tile_cell ()
#1  0x000055555555aba8 in sprite_blocking_check ()
#2  0x000055555556d66b in actor_wt_green_roamer_worm ()
#3  0x000055555555a996 in actor_update ()
#4  0x000055555555aaa6 in actor_update_all ()
#5  0x000055555555eb54 in executeTick ()
#6  0x000055555555ec53 in game_loop ()
#7  0x000055555555b061 in main ()

This happened when touching a green creature (after having touched many already and collecting points). The first time it happened when as far as I could see I just jumped over an exit without touching anything special.

yuv422 commented 4 years ago

Hi @jschwartzenberg , I'm having trouble replicating this issue. I can't seem to get it to crash no matter how many green worms I hit on that level. Would you be able to compile with debug symbols on -g and try again? It might help me narrow down the offending logic.

yuv422 commented 4 years ago

I did find a buffer read out of bounds when playing that level. I've fixed it on commit 1b5291870b46d22067092ce7b721803b5fa1c7d3

Maybe this was causing your issue? Though I can see how.

jschwartzenberg commented 4 years ago

I managed to reproduce it with debug symbols:

$ gdb ./cosmo_engine
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 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 ./cosmo_engine...done.
(gdb) r
Starting program: /home/julius/checkouts/cosmo-engine/build/cosmo_engine 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffeac70700 (LWP 23393)]
[New Thread 0x7ffff7f93700 (LWP 23394)]
[New Thread 0x7fffea46f700 (LWP 23395)]
audio_init(): opened=1 times  frequency=22050Hz  format=S16LSB  channels=1
Loading 228 status tiles.
Loading 750 player tiles.
Loading 1, player tile info records.
Loaded 4797 actor tiles.
Loading 267, actor tile info records.
Loading 2000 map bg tiles.
Loading 1000 map fg tiles.
Loading 1607 cartoon tiles.
Loading 1, cartoon tile info records.
Loading 100 font tiles.
Total Sfx 72
SOUNDS.MNI, 24, 0
SOUNDS2.MNI, 24, 23
SOUNDS3.MNI, 24, 46
Failed opening './COSMO1.SV2'
Failed opening './COSMO1.SV3'
Failed opening './COSMO1.SV4'
Failed opening './COSMO1.SV5'
Failed opening './COSMO1.SV6'
Failed opening './COSMO1.SV7'
Failed opening './COSMO1.SV8'
Failed opening './COSMO1.SV9'
Level 1: rain=0, backdrop_index=11, bg_x_scroll=64, bg_y_scroll=0, pal_anim_type=0, music_index=8
Loading 720 background tiles.
map width (in tiles): 512
Level 3: rain=0, backdrop_index=13, bg_x_scroll=64, bg_y_scroll=128, pal_anim_type=0, music_index=10
Loading 720 background tiles.
map width (in tiles): 512

Thread 1 "cosmo_engine" received signal SIGSEGV, Segmentation fault.
0x000055555555f367 in map_get_tile_cell (x=131, y=-54) at /home/julius/checkouts/cosmo-engine/src/map.c:49
49          return map_data[x + y * map_width_in_tiles];
(gdb) bt
#0  0x000055555555f367 in map_get_tile_cell (x=131, y=-54) at /home/julius/checkouts/cosmo-engine/src/map.c:49
#1  0x000055555555aba8 in sprite_blocking_check (blocking_dir=0, actorInfoIndex=69, frame_num=0, x_pos=131, y_pos=-52)
    at /home/julius/checkouts/cosmo-engine/src/actor.c:1432
#2  0x000055555556d66b in actor_wt_green_roamer_worm (actor=0x555555790f90 <actors+19728>)
    at /home/julius/checkouts/cosmo-engine/src/actor_worktype.c:2149
#3  0x000055555555a996 in actor_update (actor=0x555555790f90 <actors+19728>)
    at /home/julius/checkouts/cosmo-engine/src/actor.c:1388
#4  0x000055555555aaa6 in actor_update_all () at /home/julius/checkouts/cosmo-engine/src/actor.c:1412
#5  0x000055555555eb54 in executeTick () at /home/julius/checkouts/cosmo-engine/src/game.c:186
#6  0x000055555555ec53 in game_loop () at /home/julius/checkouts/cosmo-engine/src/game.c:242
#7  0x000055555555b061 in main (argc=1, argv=0x7fffffffdf78) at /home/julius/checkouts/cosmo-engine/src/main.c:53

Note that I did not update the sources, so possible it's the issue you already found.

yuv422 commented 4 years ago

Cool thanks for the added info. I've found your issue now. I just need to rework some logic to fix it. I wasn't correctly checking actors that go above the top of the map. This is possible for worms in this bonus level. :)

yuv422 commented 4 years ago

ok this should be fixed now :)

jschwartzenberg commented 4 years ago

Just checking, are enemies supposed to walk around in a pit here? image The blue guy just keeps rolling around on the left.

jschwartzenberg commented 4 years ago

I suspect the handling is not right. It seems Cosmo himself can also stand in all the holes now: image

yuv422 commented 4 years ago

Hmm yeah that makes sense. I changed all out of map tiles to return blocked. I think I'll need to rework that a bit.

yuv422 commented 4 years ago

Ok this should be fixed by c6b944717ed652a47a14be2567742dbf82664f1d