Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I need some help understanding what caused Minecraft to crash.

 

Crash:

 

Description: Updating screen events

 

java.lang.StackOverflowError

at net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent.getListenerList(PlayBackgroundMusicEvent.java)

at net.minecraftforge.event.EventBus.post(EventBus.java:105)

at net.minecraftforge.client.event.sound.SoundEvent.getResult(SoundEvent.java:16)

at xenocider.grooves.handler.MainEventHandler.onPlayBackgroundMusic(MainEventHandler.java:65)

at net.minecraftforge.event.ASMEventHandler_5_MainEventHandler_onPlayBackgroundMusic_PlayBackgroundMusicEvent.invoke(.dynamic)

at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39)

at net.minecraftforge.event.EventBus.post(EventBus.java:108)

at net.minecraftforge.client.event.sound.SoundEvent.getResult(SoundEvent.java:16)

 

 

The crash was triggered after the code

MainEventHandler.soundManager.playMusic(MusicHandler.currentSong);

was run.

 

Some of my code that I think might be the problem:

 

EventListener Class:

    @ForgeSubscribe
    public void onPlayBackgroundMusic(PlayBackgroundMusicEvent event) {
        SoundPoolEntry playingSong = SoundEvent.getResult(event);
        if (playingSong.getSoundName() == MusicHandler.currentSong.getSoundName()) {
            MusicHandler.goToNextSong();
        }
    }

 

Base Class SoundManager modified code:

    public void playMusic(SoundPoolEntry currentSong) {
        currentSong = SoundEvent.getResult(new PlayBackgroundMusicEvent(this, currentSong));
        if (currentSong != null)
        {
        this.sndSystem.backgroundMusic("BgMusic", currentSong.getSoundUrl(), currentSong.getSoundName(), false);
        this.sndSystem.setVolume("BgMusic", this.options.musicVolume);
        this.sndSystem.play("BgMusic");
        }
    }

 

Anything that would help understand what caused the StackOverflow error would be appreciated. Thanks!

Aren't you just saying that if the current song = the current song then go to the next song, making it constantly go to the next song, on and on?

 

"StackOverflow" Usually means you are getting stuck in an infinite loop somewhere.

You could try placing a breakpoint and see where it leads you

If you guys dont get it.. then well ya.. try harder...

  • Author

No goToNextSong() just makes it so that the next time it runs playMusic(MusicHandler.currentSong) it will play the next song after it. I'm not the best at naming my methods and variables.

 

This is what happens in goToNextSong:

    public static void goToNextSong() {
        if (currentSong == null || currentSongInt == MainEventHandler.musicSoundPoolEntryArray.length) {currentSong = MainEventHandler.musicSoundPoolEntryArray[0]; currentSongInt = 0;}
        else {
            currentSong = MainEventHandler.musicSoundPoolEntryArray[currentSongInt + 1];
            currentSongInt = currentSongInt + 1;
        }
        LogHelper.info("Going to next song.");
    }

 

EDIT: I added a logger to the PlayBackgroundMusicEvent and it was spammed a lot  of times before the game crashed. So somehow the PlayBackgroundMusicEvent keeps on getting triggered in a endless loop.

Hi

 

I think Mazetar is probably right, your code is effectively calling itself in a loop.

 

You could confirm this by adding a few more logging statements to your PlayBackgroundMusicEvent.  Or a breakpoint.

 

-TGG

  • Author

Yeah it is looping PlayBackgroundMusicEvent for some reason. I edited my reply right when you replied. Any ideas why this is happening and how could I fix it?

getSoundName() ==

Use .equals(Object) instead. String are immutable.

 

By the way, use event.source to get the sound played, and set event.result to change to the new sound.

 

 

  • Author

Thank you! It was the event.result that was continuously running the event. Changing it to event.source solved it!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.