From f0bebdcc9d5d7376bd1bcb8dfd63446205ea50a8 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 16 Dec 2014 14:54:25 -0800 Subject: [PATCH] Infinite WAV loading fix --- legacy/project/src/common/Audio.cpp | 5 ++++- project/src/audio/format/WAV.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/legacy/project/src/common/Audio.cpp b/legacy/project/src/common/Audio.cpp index add0de9a0..12dc4d245 100644 --- a/legacy/project/src/common/Audio.cpp +++ b/legacy/project/src/common/Audio.cpp @@ -501,6 +501,9 @@ namespace nme bool foundData = false; while (!foundData) { + // Save the current position indicator of the stream + currentHead = ftell(f); + //Read in the the last byte of data before the sound file result = fread(&wave_data, sizeof(WAVE_Data), 1, f); @@ -518,7 +521,7 @@ namespace nme //fseek(f, wave_data.subChunkSize, SEEK_CUR); //fseek(f, wave_data.subChunkSize, SEEK_CUR); // Goto next chunk. - fseek(f, currentHead + sizeof(WAVE_Data) + wave_format.subChunkSize, SEEK_SET); + fseek(f, currentHead + sizeof(WAVE_Data) + wave_data.subChunkSize, SEEK_SET); } else { diff --git a/project/src/audio/format/WAV.cpp b/project/src/audio/format/WAV.cpp index 404adbc57..be336943a 100644 --- a/project/src/audio/format/WAV.cpp +++ b/project/src/audio/format/WAV.cpp @@ -83,7 +83,6 @@ namespace lime { while (!foundFormat) { currentHead = lime::ftell (file); - result = lime::fread (&wave_format, sizeof (WAVE_Format), 1, file); if (result != 1) { @@ -115,6 +114,7 @@ namespace lime { while (!foundData) { + currentHead = lime::ftell (file); result = lime::fread (&wave_data, sizeof (WAVE_Data), 1, file); if (result != 1) { @@ -126,7 +126,7 @@ namespace lime { if (wave_data.subChunkID[0] != 'd' || wave_data.subChunkID[1] != 'a' || wave_data.subChunkID[2] != 't' || wave_data.subChunkID[3] != 'a') { - lime::fseek (file, currentHead + sizeof (WAVE_Data) + wave_format.subChunkSize, SEEK_SET); + lime::fseek (file, currentHead + sizeof (WAVE_Data) + wave_data.subChunkSize, SEEK_SET); } else {