azurite-engine / Azurite

Azurite Game Engine is a 2D Java game engine built on top of LWJGL.
https://azurite-engine.github.io
MIT License
42 stars 20 forks source link

Bug Fixes in Audio Engine #88

Closed HilbertCurve closed 2 years ago

HilbertCurve commented 2 years ago

There were two bugs detected in the audio engine that crashed the whole game engine:

Thanks to @goldspark for spotting the issue.

goldspark commented 2 years ago
 Projectile projectile = new Projectile(createFriendlyProjectile(new Vector2f(ship.getPositionData()[0] , ship.getPositionData()[1])), direction, 200f);
            projectile.gameObject.addComponent(AudioListener.get());
            projectile.gameObject.addComponent(new AudioSource(Assets.getAudioBuffer("src/assets/sounds/weapon_sound2.wav")));
            projectile.gameObject.getComponent(AudioSource.class).play(0, false);

First time it spawns it works correctly. Second time it crashes:

[FATAL] {audio.AudioMaster.alGetError(AudioMaster.java:99)} AL error received: Invalid Operation
[CRASH] {scenes.ezpacegame.EzSpaceDemo.main(EzSpaceDemo.java:67) -> audio.AudioMaster.alGetError(AudioMaster.java:100)} null
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "util.LoggingThread.log(String, int)" because "util.Log.loggingThread" is null
    at util.Log.crash(Log.java:279)
    at util.Engine.showWindow(Engine.java:79)
    at scenes.ezpacegame.EzSpaceDemo.main(EzSpaceDemo.java:67)
HilbertCurve commented 2 years ago

While it's a bug that the whole engine should crash when this occurs, the AudioListener singleton should only be applied to one GameObject; generally that's the player character or some other sentinel entity. Attempting to apply it multiple times will only shift the AudioListener to the latest GameObject it's applied to, or at least it should; instead it freaks out OpenAL because applying the listener to two different objects is an Invalid Operation.

goldspark commented 2 years ago

Idea, make the audio listener load with the engine .

HilbertCurve commented 2 years ago

Hmm that makes sense. Come to think of it, I'm not sure if the audio listener should even be a component; it'd be better if it was just positioned to the camera's location. We see through the camera, so I guess we should hear through it as well.

goldspark commented 2 years ago

I did apply Audio Listener to only one game object and it crashes this is what I get:

[FATAL] {audio.AudioMaster.alGetError(AudioMaster.java:99)} AL error received: Invalid Operation
[CRASH] {scenes.ezpacegame.EzSpaceDemo.main(EzSpaceDemo.java:70) -> audio.AudioMaster.alGetError(AudioMaster.java:100)} null
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "util.LoggingThread.log(String, int)" because "util.Log.loggingThread" is null
    at util.Log.crash(Log.java:279)
    at util.Engine.showWindow(Engine.java:79)
    at scenes.ezpacegame.EzSpaceDemo.main(EzSpaceDemo.java:70)
HilbertCurve commented 2 years ago

As of the most recent commit you can no longer attach the AudioListener to game objects; it seemed like an unnecessary function that wouldn't get much use. Instead it just positions itself at the camera's location.

goldspark commented 2 years ago

Still issue:

[FATAL] {audio.AudioMaster.alGetError(AudioMaster.java:103)} AL error received: Invalid Operation
[CRASH] {scenes.ezpacegame.EzSpaceDemo.main(EzAsteroidsDemo.java:70) -> audio.AudioMaster.alGetError(AudioMaster.java:104)} null
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "util.LoggingThread.log(String, int)" because "util.Log.loggingThread" is null
    at util.Log.crash(Log.java:279)
    at util.Engine.showWindow(Engine.java:79)