(audio related?) crash

Open-source port of PoP that runs natively on Windows, Linux, etc.
Post Reply
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

(audio related?) crash

Post by Norbert »

To replicate, use nothurtspikesmaybetrick.p1r from here.
Tab to the replay, then back to the title screen, then during one of the intro notes press Tab again to crash SDLPoP (works about 33-50% of the time).
Says "malloc(): smallbin double linked list corrupted".

A core does not get dumped, so I've so far been unable to look into the issue.
strace says "+++ killed by SIGSEGV (core dumped) +++".
From what I've read, if a signal handler for SIGSEGV has been set by the application, additional actions are necessary for cores to dump.
Perhaps this explains how.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: (audio related?) crash

Post by David »

Norbert wrote: February 11th, 2020, 12:27 pm To replicate, use nothurtspikesmaybetrick.p1r from here.
Tab to the replay, then back to the title screen, then during one of the intro notes press Tab again to crash SDLPoP (works about 33-50% of the time).
Says "malloc(): smallbin double linked list corrupted".
Hey, this is odd: If I play back that file then SDLPoP will use PC Speaker sounds.
If I press Ctrl+R during that, then the rest of the game will use PC Speaker sounds as well!
The crash happens only if the intro music is played using the PC Speaker.

So this is really two bugs in one:
#1: SDLPoP switching to PC Speaker sounds. (Maybe that's how this p1r was recorded? But the sound_flags variable is not even saved in replays!)
#2: SDLPoP crashing if the PC Speaker version of the intro music is interrupted by Tab.
Norbert wrote: February 11th, 2020, 12:27 pm From what I've read, if a signal handler for SIGSEGV has been set by the application, additional actions are necessary for cores to dump.
SDLPoP doesn't set signal handlers, although SDL might do so.


A possible fix I found for #2 is to add a line to the beginning of start_replay()

Code: Select all

 void start_replay() {
+	stop_sounds();
 	if (!enable_replay) return;
However, now I can't reproduce the bug anymore, not even if I undo this fix!
Maybe because I accidentally pressed Rebuild All in Dev-C++? (It's the equivalent of make clean + make.)


I'm also starting to figure out why #1 happens:

The file nothurtspikesmaybetrick.p1r contains a mod name: "Maze Of Persia".
Now, the load_all_sounds() function loads sounds differently if a custom levelset is in use.
The intention is that first it loads sounds from the mod folder, then it loads sounds from the SDLPoP data folder.
(Why? This was not needed for other DAT files.)
But what happens instead is that the first part (called "loads sounds from the mod folder") will somehow load sounds from the data/IBM_SND* folder!
Then the second part won't load any sounds because they are already loaded.

On a related note, open_dat() will never open a file from a mod folder indicated by a playback file, because mod_data_path is filled only in load_mod_options(), which is called only from pop_main() once at startup!
Therefore in the following line in open_dat():

Code: Select all

			snprintf(filename_mod, sizeof(filename_mod), "%s/%s", mod_data_path, filename);
filename_mod will always start with "/", thus SDLPoP will look for the file in the root directory!

The solution I found is to add a line to apply_replay_options():

Code: Select all

+	load_mod_options();
 	reload_resources();
 }
Somehow the non-empty mod_data_path will now prevent SDLPoP from using the data/IBM_SND* folder when it should use only the mod folder ("first part" above), even if "mods/Maze Of Persia" doesn't exist.
But I don't know why.
The file didn't exist in the root directory either, yet in that case SDLPoP behaved differently.
I might look into this another day, but not now, because one hour of debugging is more than enough for a day. :)
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1782
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: (audio related?) crash

Post by atrueprincefanfrom18 »

David wrote: February 15th, 2020, 7:50 pm
Norbert wrote: February 11th, 2020, 12:27 pm To replicate, use nothurtspikesmaybetrick.p1r from here.
Tab to the replay, then back to the title screen, then during one of the intro notes press Tab again to crash SDLPoP (works about 33-50% of the time).
Says "malloc(): smallbin double linked list corrupted".
Hey, this is odd: If I play back that file then SDLPoP will use PC Speaker sounds.
If I press Ctrl+R during that, then the rest of the game will use PC Speaker sounds as well!
The crash happens only if the intro music is played using the PC Speaker.

So this is really two bugs in one:
#1: SDLPoP switching to PC Speaker sounds. (Maybe that's how this p1r was recorded? But the sound_flags variable is not even saved in replays!)
#2: SDLPoP crashing if the PC Speaker version of the intro music is interrupted by Tab.
Norbert wrote: February 11th, 2020, 12:27 pm From what I've read, if a signal handler for SIGSEGV has been set by the application, additional actions are necessary for cores to dump.
SDLPoP doesn't set signal handlers, although SDL might do so.


A possible fix I found for #2 is to add a line to the beginning of start_replay()

Code: Select all

 void start_replay() {
+	stop_sounds();
 	if (!enable_replay) return;
However, now I can't reproduce the bug anymore, not even if I undo this fix!
Maybe because I accidentally pressed Rebuild All in Dev-C++? (It's the equivalent of make clean + make.)


I'm also starting to figure out why #1 happens:

The file nothurtspikesmaybetrick.p1r contains a mod name: "Maze Of Persia".
Now, the load_all_sounds() function loads sounds differently if a custom levelset is in use.
The intention is that first it loads sounds from the mod folder, then it loads sounds from the SDLPoP data folder.
(Why? This was not needed for other DAT files.)
But what happens instead is that the first part (called "loads sounds from the mod folder") will somehow load sounds from the data/IBM_SND* folder!
Then the second part won't load any sounds because they are already loaded.

On a related note, open_dat() will never open a file from a mod folder indicated by a playback file, because mod_data_path is filled only in load_mod_options(), which is called only from pop_main() once at startup!
Therefore in the following line in open_dat():

Code: Select all

			snprintf(filename_mod, sizeof(filename_mod), "%s/%s", mod_data_path, filename);
filename_mod will always start with "/", thus SDLPoP will look for the file in the root directory!

The solution I found is to add a line to apply_replay_options():

Code: Select all

+	load_mod_options();
 	reload_resources();
 }
Somehow the non-empty mod_data_path will now prevent SDLPoP from using the data/IBM_SND* folder when it should use only the mod folder ("first part" above), even if "mods/Maze Of Persia" doesn't exist.
But I don't know why.
The file didn't exist in the root directory either, yet in that case SDLPoP behaved differently.
I might look into this another day, but not now, because one hour of debugging is more than enough for a day. :)
Hi David, just in case this might be useful for you:

Originally, I was going to publish this mod as Maze Of Persia. But then later, as there were timing tricks, I published it as "Time Is The Key". When I recorded the p1r file, the directory name was Maze Of Persia. Before publishing I changed to "Time Is The Key".

Also, when I changed the folder name, I replayed the p1r file using Tab... Just in case that is useful to you...

I don't know what the issue is, what you are trying to solve, but as you wrote "Maze Of Persia" in the post, I thought it is better to inform you this!
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: (audio related?) crash

Post by David »

David wrote: February 15th, 2020, 7:50 pm #2: SDLPoP crashing if the PC Speaker version of the intro music is interrupted by Tab.
Fixed: https://github.com/NagyD/SDLPoP/commit/ ... e8d58742e4
David wrote: February 15th, 2020, 7:50 pm #1: SDLPoP switching to PC Speaker sounds. (Maybe that's how this p1r was recorded? But the sound_flags variable is not even saved in replays!)
Fixed: https://github.com/NagyD/SDLPoP/commit/ ... a534b25166

@Norbert, can you please check if this fixes the bugs for you as well?

You should also test this:
Start SDLPoP with the stdsnd parameter to use PC Speaker sounds, then press Tab while the intro music is playing.
This shouldn't crash SDLPoP either.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: (audio related?) crash

Post by Norbert »

David wrote: February 23rd, 2020, 10:34 am@Norbert, can you please check if this fixes the bugs for you as well?
Yes, also when starting with "stdsnd".

New is also that it says "Mod 'Maze Of Persia' not found" on the console.
And the replay no longer uses PC speaker sounds (except when starting with "stdsnd").
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: (audio related?) crash

Post by David »

Norbert wrote: February 23rd, 2020, 2:48 pm
David wrote: February 23rd, 2020, 10:34 am@Norbert, can you please check if this fixes the bugs for you as well?
Yes, also when starting with "stdsnd".
That's good to know!
Norbert wrote: February 23rd, 2020, 2:48 pm New is also that it says "Mod 'Maze Of Persia' not found" on the console.
Yes, that's because the P1R file contains this mod name.
The reason it didn't appear before my fixes is because SDLPoP "forgot" to set mod_data_path after loading a P1R file, thus it didn't even try to access the folder of that mod.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: (audio related?) crash

Post by David »

Unfortunately the fix to #1 (switching to PC Speaker sounds) is not perfect.

If I start SDLPoP from a folder which is not its own folder and contains no PoP files then it will *still* use PC Speaker sounds!

Note that in SDLPoP's data folder, IBM_SND* are in folders, while DIGISND* and MIDISND* are in DAT files.
So it seems SDLPoP can't load DAT files from its data folder if the data folder is not in the current directory.

Another consequence of the same bug is that if I rename the data/GUARD folder then SDLPoP won't try to open data/GUARD.DAT and the guards will become invisible.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: (audio related?) crash

Post by David »

David wrote: February 29th, 2020, 7:41 pm If I start SDLPoP from a folder which is not its own folder and contains no PoP files then it will *still* use PC Speaker sounds!
That has been fixed by this commit: https://github.com/NagyD/SDLPoP/commit/ ... 23afa655ec
"On Windows, use Unicode/UTF-8 for stat()."

This problem appeared because I keep SDLPoP in a path which contains a non-ASCII character.
(See also viewtopic.php?f=73&t=4715&p=33100&hilit ... cii#p33100 and viewtopic.php?f=126&t=4173&p=22886&hili ... cii#p22886 )
Post Reply