Any ideas why almp3 crashes (on the poll of the mp3, in the decode function)? Here is the relevant mp3 code:
| 1 | class MP3Play : public Song |
| 2 | { |
| 3 | //IMPLEMENT_SONGTYPE(WavePlay) |
| 4 | public: |
| 5 | static MusicEngine::Song *Factory(const string& filename) { return new MP3Play(filename); } |
| 6 | |
| 7 | public: |
| 8 | ALMP3_MP3 *mp3; |
| 9 | |
| 10 | MP3Play(const string& filename) : mp3(NULL) |
| 11 | { |
| 12 | printf("Loading %s\n", filename.c_str()); |
| 13 | PACKFILE *mp3f = pack_fopen(filename.c_str(), "r"); |
| 14 | if(!mp3f) |
| 15 | printf("hmmmmmm\n"); |
| 16 | int size = file_size(filename.c_str()); |
| 17 | char *mp3data = new char[size]; |
| 18 | size = pack_fread(mp3data, size, mp3f); |
| 19 | pack_fclose(mp3f); |
| 20 | |
| 21 | if((mp3 = almp3_create_mp3(mp3data, size)) == NULL) |
| 22 | printf("almp3_create_mp3 failed\n"); |
| 23 | |
| 24 | delete mp3data; |
| 25 | } |
| 26 | |
| 27 | ~MP3Play() |
| 28 | { |
| 29 | almp3_destroy_mp3(mp3); |
| 30 | mp3 = NULL; |
| 31 | } |
| 32 | |
| 33 | void Play() |
| 34 | { |
| 35 | if(mp3) |
| 36 | { |
| 37 | printf("Playing...\n"); |
| 38 | if(almp3_play_ex_mp3(mp3, 32768, 255, 127, 1000, 0) == ALMP3_PLAY_BUFFERTOOSMALL) |
| 39 | printf("ALMP3_PLAY_BUFFERTOOSMALL\n"); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void Stop() |
| 44 | { |
| 45 | almp3_stop_mp3(mp3); |
| 46 | } |
| 47 | |
| 48 | bool Tick() |
| 49 | { |
| 50 | printf("\rPlaying mp3"); |
| 51 | |
| 52 | int poll = 0; |
| 53 | if(mp3) |
| 54 | poll = almp3_poll_mp3(mp3); |
| 55 | |
| 56 | if(poll == ALMP3_POLL_PLAYJUSTFINISHED || poll == ALMP3_POLL_NOTPLAYING || poll == ALMP3_POLL_INTERNALERROR || !mp3) |
| 57 | return false; |
| 58 | return true; |
| 59 | } |
| 60 | }; |
and the not-so-helpful(tm) backtrace:
songtest01.exe caused an Access Violation at location 77c46fa3 in module msvcrt.dll Reading from location 02480930. Registers: eax=02481030 ebx=003df6c8 ecx=000001c0 edx=00000000 esi=02480930 edi=003df7c0 eip=77c46fa3 esp=0022fcd0 ebp=0022fcd8 iopl=0 nv up ei pl nz ac po nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00200216 Call stack: 77C46FA3 msvcrt.dll:77C46FA3 memcpy 10005A67 almp3.dll:10005A67 decodeMP3
[EDIT] Duh, I shouldn't post so quickly. It turns out mp3data has to stick around, so I made it global in the class and now delete in the destructor.