Ticket #8286: player_v2a_crashfix.diff

File player_v2a_crashfix.diff, 16.1 KB (added by SF/quietust, 21 years ago)

player_v2a fix

  • scummvm/scumm/player_v2a.cpp

    diff -ur scummvm/scumm/player_v2a.cpp ..\scummvm/scumm/player_v2a.cpp
    ..\  
    5757public:
    5858        V2A_Sound() : _id(0), _mod(NULL) { }
    5959
     60        virtual V2A_Sound *copy() = 0;
    6061        virtual void start(Player_MOD *mod, int id, const byte *data) = 0;
    6162        virtual bool update() = 0;
    6263        virtual void stop() = 0;
     
    6768
    6869class V2A_Sound_Unsupported : public V2A_Sound {
    6970public:
     71        V2A_Sound_Unsupported(V2A_Sound_Unsupported *other) { }
     72        virtual V2A_Sound *copy() {
     73                return new V2A_Sound_Unsupported(this);
     74        }
     75        V2A_Sound_Unsupported() { }
    7076        virtual void start(Player_MOD *mod, int id, const byte *data) {
    7177                warning("player_v2a - sound %i not supported yet", id);
    7278        }
     
    7783template<int numChan>
    7884class V2A_Sound_Base : public V2A_Sound {
    7985public:
     86        V2A_Sound_Base (V2A_Sound_Base *other) :
     87                _offset(other->_offset), _size(other->_size), _data(0) { }
    8088        V2A_Sound_Base() : _offset(0), _size(0), _data(0) { }
    8189        V2A_Sound_Base(uint16 offset, uint16 size) : _offset(offset), _size(size), _data(0) { }
    8290        virtual void stop() {
     
    96104
    97105class V2A_Sound_Music : public V2A_Sound {
    98106public:
     107        V2A_Sound_Music (V2A_Sound_Music *other) :
     108                _instoff(other->_instoff), _voloff(other->_voloff), _chan1off(other->_chan1off), _chan2off(other->_chan2off), _chan3off(other->_chan3off), _chan4off(other->_chan4off), _sampoff(other->_sampoff), _looped(other->_looped) { }
     109        virtual V2A_Sound *copy() {
     110                return new V2A_Sound_Music(this);
     111        }
    99112        V2A_Sound_Music(uint16 instoff, uint16 voloff, uint16 chan1off, uint16 chan2off, uint16 chan3off, uint16 chan4off, uint16 sampoff, bool looped) :
    100113                _instoff(instoff), _voloff(voloff), _chan1off(chan1off), _chan2off(chan2off), _chan3off(chan3off), _chan4off(chan4off), _sampoff(sampoff), _looped(looped) { }
    101114        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    223236
    224237class V2A_Sound_Single : public V2A_Sound_Base<1> {
    225238public:
     239        V2A_Sound_Single (V2A_Sound_Single *other) :
     240                V2A_Sound_Base<1>(other), _freq(other->_freq), _vol(other->_vol) { }
     241        virtual V2A_Sound *copy() {
     242                return new V2A_Sound_Single(this);
     243        }
    226244        V2A_Sound_Single(uint16 offset, uint16 size, uint16 freq, uint8 vol) :
    227245                V2A_Sound_Base<1>(offset, size), _freq(freq), _vol(vol) { }
    228246        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    251269
    252270class V2A_Sound_SingleLooped : public V2A_Sound_Base<1> {
    253271public:
     272        V2A_Sound_SingleLooped (V2A_Sound_SingleLooped *other) :
     273                V2A_Sound_Base<1>(other), _loopoffset(other->_loopoffset), _loopsize(other->_loopsize), _freq(other->_freq), _vol(other->_vol) { }
     274        virtual V2A_Sound *copy() {
     275                return new V2A_Sound_SingleLooped(this);
     276        }
    254277        V2A_Sound_SingleLooped(uint16 offset, uint16 size, uint16 freq, uint8 vol, uint16 loopoffset, uint16 loopsize) :
    255278                V2A_Sound_Base<1>(offset, size), _loopoffset(loopoffset), _loopsize(loopsize), _freq(freq), _vol(vol) { }
    256279        V2A_Sound_SingleLooped(uint16 offset, uint16 size, uint16 freq, uint8 vol) :
     
    276299
    277300class V2A_Sound_MultiLooped : public V2A_Sound_Base<2> {
    278301public:
     302        V2A_Sound_MultiLooped (V2A_Sound_MultiLooped *other) :
     303                V2A_Sound_Base<2>(other), _freq1(other->_freq1), _vol1(other->_vol1), _freq2(other->_freq2), _vol2(other->_vol2) { }
     304        virtual V2A_Sound *copy() {
     305                return new V2A_Sound_MultiLooped(this);
     306        }
    279307        V2A_Sound_MultiLooped(uint16 offset, uint16 size, uint16 freq1, uint8 vol1, uint16 freq2, uint8 vol2) :
    280308                V2A_Sound_Base<2>(offset, size), _freq1(freq1), _vol1(vol1), _freq2(freq2), _vol2(vol2) { }
    281309        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    303331
    304332class V2A_Sound_MultiLoopedDuration : public V2A_Sound_MultiLooped {
    305333public:
     334        V2A_Sound_MultiLoopedDuration (V2A_Sound_MultiLoopedDuration *other) :
     335                V2A_Sound_MultiLooped(other), _duration(other->_duration) { }
     336        virtual V2A_Sound *copy() {
     337                return new V2A_Sound_MultiLoopedDuration(this);
     338        }
    306339        V2A_Sound_MultiLoopedDuration(uint16 offset, uint16 size, uint16 freq1, uint8 vol1, uint16 freq2, uint8 vol2, uint16 numframes) :
    307340                V2A_Sound_MultiLooped(offset, size, freq1, vol1, freq2, vol2), _duration(numframes) { }
    308341        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    324357
    325358class V2A_Sound_SingleLoopedPitchbend : public V2A_Sound_Base<1> {
    326359public:
     360        V2A_Sound_SingleLoopedPitchbend(V2A_Sound_SingleLoopedPitchbend *other) :
     361                V2A_Sound_Base<1>(other), _freq1(other->_freq1), _freq2(other->_freq2), _vol(other->_vol), _step(other->_step) { }
     362        virtual V2A_Sound *copy() {
     363                return new V2A_Sound_SingleLoopedPitchbend(this);
     364        }
    327365        V2A_Sound_SingleLoopedPitchbend(uint16 offset, uint16 size, uint16 freq1, uint16 freq2, uint8 vol, uint8 step) :
    328366                V2A_Sound_Base<1>(offset, size), _freq1(freq1), _freq2(freq2), _vol(vol), _step(step) { }
    329367        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    363401
    364402class V2A_Sound_Special_FastPitchbendDownAndFadeout : public V2A_Sound_Base<1> {
    365403public:
     404        V2A_Sound_Special_FastPitchbendDownAndFadeout(V2A_Sound_Special_FastPitchbendDownAndFadeout *other) :
     405                V2A_Sound_Base<1>(other), _freq(other->_freq), _vol(other->_vol) { }
     406        virtual V2A_Sound *copy() {
     407                return new V2A_Sound_Special_FastPitchbendDownAndFadeout(this);
     408        }
    366409        V2A_Sound_Special_FastPitchbendDownAndFadeout(uint16 offset, uint16 size, uint16 freq, uint8 vol) :
    367410                V2A_Sound_Base<1>(offset, size), _freq(freq), _vol(vol) { }
    368411        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    394437
    395438class V2A_Sound_Special_LoopedFadeinFadeout : public V2A_Sound_Base<1> {
    396439public:
     440        V2A_Sound_Special_LoopedFadeinFadeout(V2A_Sound_Special_LoopedFadeinFadeout *other) :
     441                V2A_Sound_Base<1>(other), _freq(other->_freq), _fade1(other->_fade1), _fade2(other->_fade2) { }
     442        virtual V2A_Sound *copy() {
     443                return new V2A_Sound_Special_LoopedFadeinFadeout(this);
     444        }
    397445        V2A_Sound_Special_LoopedFadeinFadeout(uint16 offset, uint16 size, uint16 freq, uint8 fadeinrate, uint8 fadeoutrate) :
    398446                V2A_Sound_Base<1>(offset, size), _freq(freq), _fade1(fadeinrate), _fade2(fadeoutrate) { }
    399447        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    432480
    433481class V2A_Sound_Special_MultiLoopedFadeinFadeout : public V2A_Sound_Base<2> {
    434482public:
     483        V2A_Sound_Special_MultiLoopedFadeinFadeout(V2A_Sound_Special_MultiLoopedFadeinFadeout *other) :
     484                V2A_Sound_Base<2>(other), _freq1(other->_freq1), _freq2(other->_freq2), _fade1(other->_fade1), _fade2(other->_fade2) { }
     485        virtual V2A_Sound *copy() {
     486                return new V2A_Sound_Special_MultiLoopedFadeinFadeout(this);
     487        }
    435488        V2A_Sound_Special_MultiLoopedFadeinFadeout(uint16 offset, uint16 size, uint16 freq1, uint16 freq2, uint8 fadeinrate, uint8 fadeoutrate) :
    436489                V2A_Sound_Base<2>(offset, size), _freq1(freq1), _freq2(freq2), _fade1(fadeinrate), _fade2(fadeoutrate) { }
    437490        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    475528
    476529class V2A_Sound_Special_PitchbendDownThenFadeout : public V2A_Sound_Base<1> {
    477530public:
     531        V2A_Sound_Special_PitchbendDownThenFadeout(V2A_Sound_Special_PitchbendDownThenFadeout *other) :
     532                V2A_Sound_Base<1>(other), _freq1(other->_freq1), _freq2(other->_freq2), _step(other->_step) { }
     533        virtual V2A_Sound *copy() {
     534                return new V2A_Sound_Special_PitchbendDownThenFadeout(this);
     535        }
    478536        V2A_Sound_Special_PitchbendDownThenFadeout(uint16 offset, uint16 size, uint16 freq1, uint16 freq2, uint16 step) :
    479537                V2A_Sound_Base<1>(offset, size), _freq1(freq1), _freq2(freq2), _step(step) { }
    480538        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    508566
    509567class V2A_Sound_Special_PitchbendDownAndBackUp : public V2A_Sound_Base<1> {
    510568public:
     569        V2A_Sound_Special_PitchbendDownAndBackUp(V2A_Sound_Special_PitchbendDownAndBackUp *other) :
     570                V2A_Sound_Base<1>(other), _freq1(other->_freq1), _freq2(other->_freq2), _step(other->_step), _vol(other->_vol) { }
     571        virtual V2A_Sound *copy() {
     572                return new V2A_Sound_Special_PitchbendDownAndBackUp(this);
     573        }
    511574        V2A_Sound_Special_PitchbendDownAndBackUp(uint16 offset, uint16 size, uint16 freq1, uint16 freq2, uint16 step, uint8 vol) :
    512575                V2A_Sound_Base<1>(offset, size), _freq1(freq1), _freq2(freq2), _step(step), _vol(vol) { }
    513576        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    551614
    552615class V2A_Sound_Special_SlowPitchbendDownAndFadeout : public V2A_Sound_Base<1> {
    553616public:
     617        V2A_Sound_Special_SlowPitchbendDownAndFadeout(V2A_Sound_Special_SlowPitchbendDownAndFadeout *other) :
     618                V2A_Sound_Base<1>(other), _freq1(other->_freq1), _freq2(other->_freq2) { }
     619        virtual V2A_Sound *copy() {
     620                return new V2A_Sound_Special_SlowPitchbendDownAndFadeout(this);
     621        }
    554622        V2A_Sound_Special_SlowPitchbendDownAndFadeout(uint16 offset, uint16 size, uint16 freq1, uint16 freq2) :
    555623                V2A_Sound_Base<1>(offset, size), _freq1(freq1), _freq2(freq2) { }
    556624        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    583651
    584652class V2A_Sound_Special_MultiLoopedDurationMulti : public V2A_Sound_Base<2> {
    585653public:
     654        V2A_Sound_Special_MultiLoopedDurationMulti(V2A_Sound_Special_MultiLoopedDurationMulti *other) :
     655                V2A_Sound_Base<2>(other), _freq1(other->_freq1), _vol1(other->_vol1), _freq2(other->_freq2), _vol2(other->_vol2), _duration(other->_duration), _playwidth(other->_playwidth), _loopwidth(other->_loopwidth) { }
     656        virtual V2A_Sound *copy() {
     657                return new V2A_Sound_Special_MultiLoopedDurationMulti(this);
     658        }
    586659        V2A_Sound_Special_MultiLoopedDurationMulti(uint16 offset, uint16 size, uint16 freq1, uint8 vol1, uint16 freq2, uint8 vol2, uint16 numframes, uint8 playwidth, uint8 loopwidth) :
    587660                V2A_Sound_Base<2>(offset, size), _freq1(freq1), _vol1(vol1), _freq2(freq2), _vol2(vol2), _duration(numframes), _playwidth(playwidth), _loopwidth(loopwidth) { }
    588661        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    636709
    637710class V2A_Sound_Special_SingleDurationMulti : public V2A_Sound_Base<1> {
    638711public:
     712        V2A_Sound_Special_SingleDurationMulti(V2A_Sound_Special_SingleDurationMulti *other) :
     713                V2A_Sound_Base<1>(other), _freq(other->_freq), _vol(other->_vol), _loopwidth(other->_loopwidth), _numloops(other->_numloops) { }
     714        virtual V2A_Sound *copy() {
     715                return new V2A_Sound_Special_SingleDurationMulti(this);
     716        }
    639717        V2A_Sound_Special_SingleDurationMulti(uint16 offset, uint16 size, uint16 freq, uint8 vol, uint8 loopwidth, uint8 numloops) :
    640718                V2A_Sound_Base<1>(offset, size), _freq(freq), _vol(vol), _loopwidth(loopwidth), _numloops(numloops) { }
    641719        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    678756
    679757class V2A_Sound_Special_SingleDurationMultiDurations : public V2A_Sound_Base<1> {
    680758public:
     759        V2A_Sound_Special_SingleDurationMultiDurations(V2A_Sound_Special_SingleDurationMultiDurations *other) :
     760                V2A_Sound_Base<1>(other), _freq(other->_freq), _vol(other->_vol), _numdurs(other->_numdurs), _durations(other->_durations), _looped(other->_looped) { }
     761        virtual V2A_Sound *copy() {
     762                return new V2A_Sound_Special_SingleDurationMultiDurations(this);
     763        }
    681764        V2A_Sound_Special_SingleDurationMultiDurations(uint16 offset, uint16 size, uint16 freq, uint8 vol, uint8 numdurs, const uint8 *durations, bool looped) :
    682765                V2A_Sound_Base<1>(offset, size), _freq(freq), _vol(vol), _numdurs(numdurs), _durations(durations), _looped(looped) { }
    683766        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    724807
    725808class V2A_Sound_Special_TwinSirenMulti : public V2A_Sound_Base<2> {
    726809public:
     810        V2A_Sound_Special_TwinSirenMulti(V2A_Sound_Special_TwinSirenMulti *other) :
     811                _offset1(other->_offset1), _size1(other->_size1), _offset2(other->_offset2), _size2(other->_size2), _freq1(other->_freq1), _freq2(other->_freq2), _vol(other->_vol) { }
     812        virtual V2A_Sound *copy() {
     813                return new V2A_Sound_Special_TwinSirenMulti(this);
     814        }
    727815        V2A_Sound_Special_TwinSirenMulti(uint16 offset1, uint16 size1, uint16 offset2, uint16 size2, uint16 freq1, uint16 freq2, uint8 vol) :
    728816                _offset1(offset1), _size1(size1), _offset2(offset2), _size2(size2), _freq1(freq1), _freq2(freq2), _vol(vol) { }
    729817        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    787875
    788876class V2A_Sound_Special_QuadSiren : public V2A_Sound_Base<4> {
    789877public:
     878        V2A_Sound_Special_QuadSiren(V2A_Sound_Special_QuadSiren *other) :
     879                _offset1(other->_offset1), _size1(other->_size1), _offset2(other->_offset2), _size2(other->_size2), _vol(other->_vol) { }
     880        virtual V2A_Sound *copy() {
     881                return new V2A_Sound_Special_QuadSiren(this);
     882        }
    790883        V2A_Sound_Special_QuadSiren(uint16 offset1, uint16 size1, uint16 offset2, uint16 size2, uint8 vol) :
    791884                _offset1(offset1), _size1(size1), _offset2(offset2), _size2(size2), _vol(vol) { }
    792885        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    858951
    859952class V2A_Sound_Special_QuadFreqLooped : public V2A_Sound_Base<4> {
    860953public:
     954        V2A_Sound_Special_QuadFreqLooped(V2A_Sound_Special_QuadFreqLooped *other) :
     955                V2A_Sound_Base<4>(other), _freq1(other->_freq1), _freq2(other->_freq2), _freq3(other->_freq3), _freq4(other->_freq4), _vol(other->_vol) { }
     956        virtual V2A_Sound *copy() {
     957                return new V2A_Sound_Special_QuadFreqLooped(this);
     958        }
    861959        V2A_Sound_Special_QuadFreqLooped(uint16 offset, uint16 size, uint16 freq1, uint16 freq2, uint16 freq3, uint16 freq4, uint8 vol) :
    862960                V2A_Sound_Base<4>(offset, size), _freq1(freq1), _freq2(freq2), _freq3(freq3), _freq4(freq4), _vol(vol) { }
    863961        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    891989
    892990class V2A_Sound_Special_QuadFreqFadeout : public V2A_Sound_Special_QuadFreqLooped {
    893991public:
     992        V2A_Sound_Special_QuadFreqFadeout(V2A_Sound_Special_QuadFreqFadeout *other) :
     993                V2A_Sound_Special_QuadFreqLooped(other), _dur(other->_dur) { }
     994        virtual V2A_Sound *copy() {
     995                return new V2A_Sound_Special_QuadFreqFadeout(this);
     996        }
    894997        V2A_Sound_Special_QuadFreqFadeout(uint16 offset, uint16 size, uint16 freq1, uint16 freq2, uint16 freq3, uint16 freq4, uint8 vol, uint16 dur) :
    895998                V2A_Sound_Special_QuadFreqLooped(offset, size, freq1, freq2, freq3, freq4, vol), _dur(dur) { }
    896999        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    9171020
    9181021class V2A_Sound_Special_SingleFadeout : public V2A_Sound_Base<1> {
    9191022public:
     1023        V2A_Sound_Special_SingleFadeout(V2A_Sound_Special_SingleFadeout *other) :
     1024                V2A_Sound_Base<1>(other), _freq(other->_freq), _vol(other->_vol) { }
     1025        virtual V2A_Sound *copy() {
     1026                return new V2A_Sound_Special_SingleFadeout(this);
     1027        }
    9201028        V2A_Sound_Special_SingleFadeout(uint16 offset, uint16 size, uint16 freq, uint8 vol) :
    9211029                V2A_Sound_Base<1>(offset, size), _freq(freq), _vol(vol) { }
    9221030        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    9431051
    9441052class V2A_Sound_Special_SlowPitchbendThenSlowFadeout : public V2A_Sound_Base<1> {
    9451053public:
     1054        V2A_Sound_Special_SlowPitchbendThenSlowFadeout(V2A_Sound_Special_SlowPitchbendThenSlowFadeout *other) :
     1055                V2A_Sound_Base<1>(other), _freq1(other->_freq1), _freq2(other->_freq2) { }
     1056        virtual V2A_Sound *copy() {
     1057                return new V2A_Sound_Special_SlowPitchbendThenSlowFadeout(this);
     1058        }
    9461059        V2A_Sound_Special_SlowPitchbendThenSlowFadeout(uint16 offset, uint16 size, uint16 freq1, uint16 freq2) :
    9471060                V2A_Sound_Base<1>(offset, size), _freq1(freq1), _freq2(freq2) { }
    9481061        virtual void start(Player_MOD *mod, int id, const byte *data) {
     
    11511264                if (!_slot[i].id)
    11521265                        continue;
    11531266                _slot[i].sound->stop();
     1267                delete _slot[i].sound;
    11541268                _slot[i].sound = NULL;
    11551269                _slot[i].id = 0;
    11561270        }
     
    11641278        if (i == -1)
    11651279                return;
    11661280        _slot[i].sound->stop();
     1281        delete _slot[i].sound;
    11671282        _slot[i].sound = NULL;
    11681283        _slot[i].id = 0;
    11691284}
     
    11831298        if (i == -1)
    11841299                return;
    11851300        _slot[i].id = nr;
    1186         _slot[i].sound = snd;
     1301        _slot[i].sound = snd->copy();
    11871302        _slot[i].sound->start(_mod,nr,data);
    11881303}
    11891304
     
    11961311        for (i = 0; i < V2A_MAXSLOTS; i++) {
    11971312                if ((_slot[i].id) && (!_slot[i].sound->update())) {
    11981313                        _slot[i].sound->stop();
     1314                        delete _slot[i].sound;
    11991315                        _slot[i].sound = NULL;
    12001316                        _slot[i].id = 0;
    12011317                }