UltraStar-Deluxe / USDX

The free and open source karaoke singing game UltraStar Deluxe, inspired by Sony SingStar™
https://usdx.eu
GNU General Public License v2.0
851 stars 161 forks source link

Problems building a feature: reload songs from disk #494

Closed kmille closed 4 years ago

kmille commented 4 years ago

Hey, I am using the master branch on Arch Linux. I am trying to build a feature: Reload songs from disk after pressing a key (and not: restart the game).

The idea: load TSongs.Create (which loads the songs) after pressing C (wich shows the credit animation).

kmille@linbox USDX master %  g d  src/screens/UScreenMain.pas
diff --git a/src/screens/UScreenMain.pas b/src/screens/UScreenMain.pas
index 0ba77ed..2343c73 100644
--- a/src/screens/UScreenMain.pas
+++ b/src/screens/UScreenMain.pas
@@ -151,6 +151,9 @@ begin
       end;

       Ord('C'): begin
+         writeln('does this work?');
+         TSongs.Create;
+         writeln('seems like?');
          FadeTo(@ScreenCredits, SoundLib.Start);
          Exit;
       end;

Result: The writeln statements are executed. But

Exception class: EAccessViolation Message: Access violation $000000000051A150 line 3494 of screens/UScreenSong.pas $000000000050D75D line 464 of screens/UScreenSong.pas $000000000050FBF3 line 1285 of screens/UScreenSong.pas $0000000000464911 line 674 of menu/UDisplay.pas $000000000047EC25 line 569 of base/UMain.pas $000000000047DD50 line 326 of base/UMain.pas $000000000047DB39 line 269 of base/UMain.pas $0000000000408401 line 404 of ultrastardx.dpr

Can you help me? Took me some time to get that far.

kmille commented 4 years ago

any hint or advise @s09bQ5 ?

s09bQ5 commented 4 years ago

You create a second object of type TSongs that overwrites some global variables in its constructor. But you don't overwrite the Songs pointer to the old TSongs object. And you should destroy the old object if you create a new one to free its memory.

kmille commented 4 years ago

thanks! I forgot to say: I'm a python guy :snake: I will try harder if I find some time.

basisbit commented 4 years ago

You'll also have to recreate the ScreenSongMenu and update all members where that screen instance or members of it are kept. You'll have to refactor/rewrite quite a bit of code to get this feature working.

kmille commented 4 years ago

Okay. I think I will give up here. But still: great software! We're having a great time with it. btw: we are building a scraper for http://usdb.animux.de/. So the in-place reload feature would be nice.