2011-09-20 31 views
1

我試圖讓我的音軌使用FMOD播放,但我一直得到未處理的異常,然後它說沒有可用的源代碼,並顯示反彙編代碼。FMOD - 沒有源代碼可用的未處理的異常

main.cpp 
     bool AudioProject::initAudio() 
    { 
     // Audio code 
     fmSound = new Sound(); 
     fmSound->initialise(); 
     fmSound->load("Music/Rocky_Theme_Tune.mp3"); 
     fmSound->play(); 
     return true; 
    } 

我把斷點放在它停下來的地方,這在初始化函數中。它甚至進入初始化函數,然後隨機休息。我想我每次都包含fmod文件,因爲去年我使用它沒有問題。

我也會發布我的sound.h/.cpp文件。

.H

#include "stdafx.h" 
#pragma once 
#include "fmod.hpp" 
#include "fmod.h" 


class Sound 
{ 
private: 
    bool on; //is sound on? 
    bool possible; //is it possible to play sound? 
    char * currentSound; //currently played sound 
    //FMOD-specific stuff 
    FMOD_RESULT result; 
    FMOD_SYSTEM * fmodsystem; 
    FMOD_SOUND * sound; 
    FMOD_CHANNEL * channel; 

public: 
    Sound(); 
    ~Sound(); 
    void initialise (void); 
    void setVolume (float v); 
    void load (const char * filename); 
    void unload (void); 
    void play (bool pause = false); 
    bool getSound (void); 
    void setPause (bool pause); 
    void setSound (bool sound); 
    void toggleSound (void); 
    void togglePause (void); 

}; 

的.cpp

#include "stdafx.h" 
#include "Sound.h" 
#include "fmod.h" 
#include "fmod.hpp" 

Sound::Sound() 
{ 
    on = true; //is sound on? 
    possible = true; //is it possible to play sound? 
    currentSound=""; //currently played sound 
    sound=0; 

} 

Sound::~Sound() 
{ 

} 

//initialises sound 
void Sound::initialise (void) 
{ 

    //create the sound system. If fails, sound is set to impossible 
    result = FMOD_System_Create(&fmodsystem); 
    if (result != FMOD_OK) 
     possible = false; 

    //if initialise the sound system. If fails, sound is set to impossible 
    if (possible) 
     result = FMOD_System_Init(fmodsystem,2, FMOD_INIT_NORMAL, 0); 

    if (result != FMOD_OK) 
     possible = false; 

    //sets initial sound volume (mute) 
    if (possible) 
     FMOD_Channel_SetVolume(channel,1.0f); 
} 

//sets the actual playing sound's volume 
void Sound::setVolume (float v) 
{ 
    if (possible && on && v >= 0.0f && v <= 1.0f) 
    { 
     FMOD_Channel_SetVolume(channel,v); 
    } 
} 

//loads a soundfile 
void Sound::load (const char * filename) 
{ 
    currentSound = (char *)filename; 
    if (possible && on) 
    { 
     result = FMOD_Sound_Release(sound); 
     result = FMOD_System_CreateStream(fmodsystem,currentSound, FMOD_SOFTWARE, 0, &sound); 
     if (result != FMOD_OK) 
      possible = false; 
    } 
} 

//frees the sound object 
void Sound::unload (void) 
{ 
    if (possible) 
    { 
     result = FMOD_Sound_Release(sound); 
    } 
} 

//plays a sound (no argument to leave pause as dafault) 
void Sound::play (bool pause) 
{ 
    if (possible && on) 
    { 
     result = FMOD_System_PlaySound(fmodsystem,FMOD_CHANNEL_FREE, sound, pause, &channel); 
     FMOD_Channel_SetMode(channel,FMOD_LOOP_NORMAL); 
    } 
} 

//toggles sound on and off 
void Sound::toggleSound (void) 
{ 
    on = !on; 
    if (on == true) 
    { 
     load(currentSound); 
     play(); 
    } 
    if (on == false) 
    { 
     unload(); 
    } 
} 

//pause or unpause the sound 
void Sound::setPause (bool pause) 
{ 
    FMOD_Channel_SetPaused (channel, pause); 
} 

//turn sound on or off 
void Sound::setSound (bool s) 
{ 
    on = s; 
} 

//toggle pause on and off 
void Sound::togglePause (void) 
{ 
    FMOD_BOOL p; 
    FMOD_Channel_GetPaused(channel,&p); 
    FMOD_Channel_SetPaused (channel,!p); 
} 

//tells whether the sound is on or off 
bool Sound::getSound (void) 
{ 
    return on; 
} 

這裏撞了南牆,任何人有什麼想法?

回答

1

您調用initialiseFMOD_Channel_SetVolume(channel,1.0f),但channel變量沒有尚未初始化時,它會通過在FMOD_System_PlaySound(fmodsystem,FMOD_CHANNEL_FREE, sound, pause, &channel);Sound::play

+0

它從來沒有達到該行代碼初始化,它打破了在第二行進入Sound :: initialise函數。結果= FMOD_System_Create(&fmodsystem); – Craig