From b39cca1c30b0424a567d3826a8038946404cf0a6 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Wed, 7 Dec 2016 14:29:08 +0300 Subject: Fixed crash in the DosBox version (because after std::vector's resize, contents is uninitialized, Valgrind has been confirmed that) --- src/adlmidi.cpp | 19 ++++++++++++++----- src/nukedopl3.h | 9 +++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index 02e78c6..4527d5c 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -48,6 +48,7 @@ #include // deque #include // exp, log, ceil #include +#include // numeric_limit #include #include @@ -57,7 +58,6 @@ #include "dbopl.h" #else #include "nukedopl3.h" -#include #endif #include "adldata.hh" @@ -202,10 +202,10 @@ struct OPL3 // 7 = percussion Hihat // 8 = percussion slave - void Poke(size_t card, unsigned index, unsigned value) + void Poke(size_t card, uint32_t index, uint32_t value) { #ifdef ADLMIDI_USE_DOSBOX_OPL - cards[card].WriteReg(index, value); + cards[card].WriteReg(index, static_cast(value)); #else OPL3_WriteReg(&cards[card], static_cast(index), static_cast(value)); #endif @@ -213,7 +213,7 @@ struct OPL3 void PokeN(size_t card, uint16_t index, uint8_t value) { #ifdef ADLMIDI_USE_DOSBOX_OPL - cards[card].WriteReg(static_cast(index), static_cast(value)); + cards[card].WriteReg(static_cast(index), value); #else OPL3_WriteReg(&cards[card], index, value); #endif @@ -428,7 +428,16 @@ struct OPL3 void Reset() { LogarithmicVolumes = false; +#ifdef ADLMIDI_USE_DOSBOX_OPL + DBOPL::Handler emptyChip; +#else + _opl3_chip emptyChip; +#endif cards.resize(NumCards); + + for(unsigned int i = 0; i < NumCards; i++) + cards[i] = emptyChip; + NumChannels = NumCards * 23; ins.resize(NumChannels, 189); pit.resize(NumChannels, 0); @@ -2841,7 +2850,7 @@ ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer *device, int sampleCount, short *out) else if(n_samples > 0) { #ifdef ADLMIDI_USE_DOSBOX_OPL - std::vector in; + std::vector in; in.resize(1024); /*n_samples * 2 */ ssize_t in_count = n_samples; #endif diff --git a/src/nukedopl3.h b/src/nukedopl3.h index e7f05ef..ea44de9 100644 --- a/src/nukedopl3.h +++ b/src/nukedopl3.h @@ -51,13 +51,13 @@ typedef struct _opl3_slot opl3_slot; typedef struct _opl3_channel opl3_channel; typedef struct _opl3_chip opl3_chip; -#pragma pack(1) struct _opl3_slot { opl3_channel *channel; opl3_chip *chip; Bit16s out; Bit16s fbmod; + Bit8u ___padding[4]; Bit16s *mod; Bit16s prout; Bit16s eg_rout; @@ -66,6 +66,7 @@ struct _opl3_slot Bit8u eg_gen; Bit8u eg_rate; Bit8u eg_ksl; + Bit8u ___padding2[6]; Bit8u *trem; Bit8u reg_vib; Bit8u reg_type; @@ -81,6 +82,7 @@ struct _opl3_slot Bit8u key; Bit32u pg_phase; Bit32u timer; + Bit8u ___padding3[4]; }; struct _opl3_channel @@ -90,13 +92,16 @@ struct _opl3_channel opl3_chip *chip; Bit16s *out[4]; Bit8u chtype; + Bit8u ___padding[1]; Bit16u f_num; Bit8u block; Bit8u fb; Bit8u con; Bit8u alg; Bit8u ksv; + Bit8u ___padding2[1]; Bit16u cha, chb; + Bit8u ___padding3[2]; }; typedef struct _opl3_writebuf @@ -104,8 +109,8 @@ typedef struct _opl3_writebuf Bit64u time; Bit16u reg; Bit8u data; + Bit8u ___padding[5]; } opl3_writebuf; -#pragma pack(0) struct _opl3_chip { -- cgit v1.2.3