Fix crash in OGG load on newer Android toolchain
This commit is contained in:
@@ -108,6 +108,7 @@ namespace lime {
|
||||
|
||||
OggVorbis_File oggFile;
|
||||
Bytes *data = NULL;
|
||||
OAL_OggMemoryFile fakeFile;
|
||||
|
||||
if (resource->path) {
|
||||
|
||||
@@ -133,7 +134,10 @@ namespace lime {
|
||||
lime::fclose (file);
|
||||
data = new Bytes (resource->path);
|
||||
|
||||
OAL_OggMemoryFile fakeFile = { data->Data (), data->Length (), 0 };
|
||||
LOG_SOUND ("hello %d\n", data->Data ());
|
||||
LOG_SOUND ("hello %d\n", data->Length ());
|
||||
|
||||
fakeFile = { data->Data (), data->Length (), 0 };
|
||||
|
||||
if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) {
|
||||
|
||||
@@ -142,11 +146,13 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
LOG_SOUND ("%s", "2");
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
OAL_OggMemoryFile fakeFile = { resource->data->Data (), resource->data->Length (), 0 };
|
||||
fakeFile = { resource->data->Data (), resource->data->Length (), 0 };
|
||||
|
||||
if (ov_open_callbacks (&fakeFile, &oggFile, NULL, 0, OAL_CALLBACKS_BUFFER) != 0) {
|
||||
|
||||
@@ -156,6 +162,8 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
LOG_SOUND ("%s", "3");
|
||||
|
||||
// 0 for Little-Endian, 1 for Big-Endian
|
||||
#ifdef HXCPP_BIG_ENDIAN
|
||||
#define BUFFER_READ_TYPE 1
|
||||
@@ -186,6 +194,8 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
LOG_SOUND ("%s", "4");
|
||||
|
||||
audioBuffer->channels = pInfo->channels;
|
||||
audioBuffer->sampleRate = pInfo->rate;
|
||||
|
||||
@@ -194,19 +204,27 @@ namespace lime {
|
||||
int dataLength = ov_pcm_total (&oggFile, -1) * audioBuffer->channels * audioBuffer->bitsPerSample / 8;
|
||||
audioBuffer->data->Resize (dataLength);
|
||||
|
||||
LOG_SOUND ("%s", "5");
|
||||
|
||||
while (bytes > 0) {
|
||||
|
||||
bytes = ov_read (&oggFile, (char *)audioBuffer->data->Data () + totalBytes, BUFFER_SIZE, BUFFER_READ_TYPE, 2, 1, &bitStream);
|
||||
LOG_SOUND ("bytes %d", bytes);
|
||||
totalBytes += bytes;
|
||||
LOG_SOUND ("totalBytes %d\n", totalBytes);
|
||||
|
||||
}
|
||||
|
||||
LOG_SOUND ("%s", "6");
|
||||
|
||||
if (dataLength != totalBytes) {
|
||||
|
||||
audioBuffer->data->Resize (totalBytes);
|
||||
|
||||
}
|
||||
|
||||
LOG_SOUND ("%s", "7");
|
||||
|
||||
ov_clear (&oggFile);
|
||||
|
||||
#undef BUFFER_READ_TYPE
|
||||
@@ -217,6 +235,8 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
LOG_SOUND ("%s", "8");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user