Let the game engine manage it's own sound scene. This is to fix bug 1415 (Patch...
authorKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Mon, 26 Jul 2004 11:54:10 +0000 (11:54 +0000)
committerKester Maddock <Christopher.Maddock.1@uni.massey.ac.nz>
Mon, 26 Jul 2004 11:54:10 +0000 (11:54 +0000)
http://projects.blender.org/tracker/index.php?func=detail&aid=1415&group_id=9&atid=125
Also release the OpenAL device & context.  These were leaked before, and would cause an assertion.

intern/SoundSystem/intern/SND_DeviceManager.cpp
intern/SoundSystem/openal/SND_OpenALDevice.cpp
intern/SoundSystem/openal/SND_OpenALDevice.h
source/blender/src/editsound.c
source/blender/src/space.c

index d6f23ff5de4c7c018e6d6f6a429db9ff148e3ff1..37487686d71664096ccf38a920cf05f3213b1ba1 100644 (file)
@@ -78,6 +78,9 @@ void SND_DeviceManager::Unsubscribe()
                delete m_instance;
                m_instance = NULL;
        }
+       
+       if (m_subscriptions < 0)
+               m_subscriptions = 0;
 }
 
 
index 9bdfeb73844b09d734affcc444add8275f75b4a6..dfac8333a338796c29f22d6b95576f71a6bf6a35 100644 (file)
@@ -205,6 +205,8 @@ ALvoid alutUnloadWAV(ALenum format,ALvoid *data,ALsizei size,ALsizei freq)
 
 
 SND_OpenALDevice::SND_OpenALDevice()
+       : m_context(NULL),
+         m_device(NULL)
 {
     /* Removed the functionality for checking if noaudio was provided on */
     /* the commandline. */
@@ -229,6 +231,7 @@ SND_OpenALDevice::SND_OpenALDevice()
                        if (m_context) {
                                alcMakeContextCurrent(m_context);
                                m_audio = true;
+                               m_device = dev;
                        }
                }
 
@@ -302,13 +305,16 @@ void SND_OpenALDevice::MakeCurrent() const
 SND_OpenALDevice::~SND_OpenALDevice()
 {
        if (m_context) {
-               alcMakeContextCurrent(m_context);
-
+               MakeCurrent();
+               
                if (m_buffersinitialized)
                        alDeleteBuffers(NUM_BUFFERS, m_buffers);
 
                if (m_sourcesinitialized)
                        alDeleteSources(NUM_SOURCES, m_sources);
+               
+               alcDestroyContext(m_context);
+               m_context = NULL;
        }
        
        // let's see if we used the cd. if not, just leave it alone
@@ -323,6 +329,13 @@ SND_OpenALDevice::~SND_OpenALDevice()
        if (m_cdrom)
                delete m_cdrom;
 #endif
+#ifdef OUDE_OPENAL
+       if (m_audio)
+               alutExit();
+#else
+       if (m_device)
+               alcCloseDevice((ALCdevice*) m_device);
+#endif
 }
 
 
@@ -570,7 +583,7 @@ void SND_OpenALDevice::StopObject(int id) const
 
        alSourcefv(m_sources[id], AL_POSITION, obpos);
        alSourcefv(m_sources[id], AL_VELOCITY, obvel);
-       
+
        alSourcef(m_sources[id], AL_GAIN, 1.0);
        alSourcef(m_sources[id], AL_PITCH, 1.0);
        alSourcei(m_sources[id], AL_LOOPING, AL_FALSE);
index 4f20580c2f34049aee462ad7e43bce2d62a74eca..4cd386cd48d956e199186c850a9c09648af2a561 100644 (file)
@@ -95,6 +95,7 @@ public:
 
 private:
        void*                   m_context;
+       void*                   m_device;
 
        unsigned int    m_buffers[NUM_BUFFERS];
        unsigned int    m_sources[NUM_SOURCES];
index b9695881068923daf1f953b6352826f9a9e09904..b409804a9f83487163b681f03a550355433b81ed 100644 (file)
@@ -514,7 +514,7 @@ int sound_get_filetype_from_header(bSound* sound, PackedFile* pf)
        {
                filetype = SAMPLE_OGG_VORBIS;
        }
-       else if ((!memcmp(buffer, "ID3", 3)) || (!memcmp(buffer, "ÿû", 2)))
+       else if ((!memcmp(buffer, "ID3", 3)) || (!memcmp(buffer, "", 2)))
        {
                filetype = SAMPLE_MP3;
        }
@@ -1015,9 +1015,6 @@ void sound_init_audio(void)
        SYS_SystemHandle hSystem = NULL;
        
        if(ghSoundScene==NULL) {
-               
-               printf("sound init audio\n");
-       
                hSystem = SYS_GetSystem();
                noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0);
                
@@ -1043,5 +1040,6 @@ void sound_exit_audio(void)
        if(ghSoundScene) {
                SND_DeleteScene(ghSoundScene);
                SND_ReleaseDevice();
+               ghSoundScene = NULL;
        }
 }
index d13ec81b4ba8cc5ffa347889dec21967c61fc6bc..0f80a21c79ac4f738076a2519dd831a3c347e249 100644 (file)
@@ -456,9 +456,9 @@ void start_game(void)
        scene_cfra_store= save_and_reset_all_scene_cfra();
        
 
-       /* sound init is save, only handles once */
-       sound_init_audio();
+       /* game engine will do its own sounds. */
        sound_stop_all_sounds();
+       sound_exit_audio();
        
        /* Before jumping into Ketsji, we configure some settings. */
        space_set_commmandline_options();