Fix race condition in lime_image_load, lime_audio_load

This commit is contained in:
Joshua Granick
2015-12-31 14:42:20 -08:00
parent 4dc0aa3db4
commit cd4d4a8f43
6 changed files with 25 additions and 14 deletions

View File

@@ -87,7 +87,7 @@ class AudioBuffer {
var audioBuffer = new AudioBuffer (); var audioBuffer = new AudioBuffer ();
audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.bitsPerSample = data.bitsPerSample;
audioBuffer.channels = data.channels; audioBuffer.channels = data.channels;
audioBuffer.data = new UInt8Array (@:privateAccess new Bytes (data.data.length, data.data.b)); audioBuffer.data = new UInt8Array (@:privateAccess new Bytes (data.length, data.b));
audioBuffer.sampleRate = data.sampleRate; audioBuffer.sampleRate = data.sampleRate;
return audioBuffer; return audioBuffer;
@@ -127,7 +127,7 @@ class AudioBuffer {
var audioBuffer = new AudioBuffer (); var audioBuffer = new AudioBuffer ();
audioBuffer.bitsPerSample = data.bitsPerSample; audioBuffer.bitsPerSample = data.bitsPerSample;
audioBuffer.channels = data.channels; audioBuffer.channels = data.channels;
audioBuffer.data = new UInt8Array (@:privateAccess new Bytes (data.data.length, data.data.b)); audioBuffer.data = new UInt8Array (@:privateAccess new Bytes (data.length, data.b));
audioBuffer.sampleRate = data.sampleRate; audioBuffer.sampleRate = data.sampleRate;
return audioBuffer; return audioBuffer;

View File

@@ -1089,7 +1089,7 @@ class Image {
if (data != null) { if (data != null) {
__fromImageBuffer (new ImageBuffer (new UInt8Array (@:privateAccess new Bytes (data.data.length, data.data.b)), data.width, data.height, data.bitsPerPixel)); __fromImageBuffer (new ImageBuffer (new UInt8Array (@:privateAccess new Bytes (data.length, data.b)), data.width, data.height, data.bitsPerPixel));
if (onload != null) { if (onload != null) {
@@ -1209,7 +1209,7 @@ class Image {
if (data != null) { if (data != null) {
var u8a = new UInt8Array (@:privateAccess new Bytes (data.data.length, data.data.b)); var u8a = new UInt8Array (@:privateAccess new Bytes (data.length, data.b));
buffer = new ImageBuffer (u8a, data.width, data.height, data.bitsPerPixel); buffer = new ImageBuffer (u8a, data.width, data.height, data.bitsPerPixel);
} }

View File

@@ -4,7 +4,6 @@
#include <hx/CFFI.h> #include <hx/CFFI.h>
#include <graphics/ImageBuffer.h> #include <graphics/ImageBuffer.h>
#include <utils/ByteArray.h>
namespace lime { namespace lime {

View File

@@ -155,6 +155,7 @@ namespace lime {
AudioBuffer audioBuffer; AudioBuffer audioBuffer;
Resource resource; Resource resource;
Bytes bytes;
if (val_is_string (data)) { if (val_is_string (data)) {
@@ -162,7 +163,7 @@ namespace lime {
} else { } else {
Bytes bytes (data); bytes = Bytes (data);
resource = Resource (&bytes); resource = Resource (&bytes);
} }
@@ -448,6 +449,7 @@ namespace lime {
#ifdef LIME_FREETYPE #ifdef LIME_FREETYPE
Resource resource; Resource resource;
Bytes bytes;
if (val_is_string (data)) { if (val_is_string (data)) {
@@ -455,7 +457,7 @@ namespace lime {
} else { } else {
Bytes bytes (data); bytes = Bytes (data);
resource = Resource (&bytes); resource = Resource (&bytes);
} }
@@ -612,6 +614,7 @@ namespace lime {
ImageBuffer buffer; ImageBuffer buffer;
Resource resource; Resource resource;
Bytes bytes;
if (val_is_string (data)) { if (val_is_string (data)) {
@@ -619,7 +622,7 @@ namespace lime {
} else { } else {
Bytes bytes (data); bytes = Bytes (data);
resource = Resource (&bytes); resource = Resource (&bytes);
} }

View File

@@ -4,9 +4,10 @@
namespace lime { namespace lime {
static int id_b;
static int id_bitsPerSample; static int id_bitsPerSample;
static int id_channels; static int id_channels;
static int id_data; static int id_length;
static int id_sampleRate; static int id_sampleRate;
static bool init = false; static bool init = false;
@@ -32,18 +33,20 @@ namespace lime {
if (!init) { if (!init) {
id_b = val_id ("b");
id_bitsPerSample = val_id ("bitsPerSample"); id_bitsPerSample = val_id ("bitsPerSample");
id_channels = val_id ("channels"); id_channels = val_id ("channels");
id_data = val_id ("data"); id_length = val_id ("length");
id_sampleRate = val_id ("sampleRate"); id_sampleRate = val_id ("sampleRate");
init = true; init = true;
} }
mValue = alloc_empty_object (); mValue = alloc_empty_object ();
alloc_field (mValue, id_b, data ? val_field (data->Value (), id_b) : alloc_null ());
alloc_field (mValue, id_bitsPerSample, alloc_int (bitsPerSample)); alloc_field (mValue, id_bitsPerSample, alloc_int (bitsPerSample));
alloc_field (mValue, id_channels, alloc_int (channels)); alloc_field (mValue, id_channels, alloc_int (channels));
alloc_field (mValue, id_data, data ? data->Value () : alloc_null ()); alloc_field (mValue, id_length, data ? val_field (data->Value (), id_length) : alloc_null ());
alloc_field (mValue, id_sampleRate, alloc_int (sampleRate)); alloc_field (mValue, id_sampleRate, alloc_int (sampleRate));
return mValue; return mValue;

View File

@@ -4,11 +4,13 @@
namespace lime { namespace lime {
static int id_b;
static int id_bitsPerPixel; static int id_bitsPerPixel;
static int id_buffer; static int id_buffer;
static int id_data; static int id_data;
static int id_format; static int id_format;
static int id_height; static int id_height;
static int id_length;
static int id_premultiplied; static int id_premultiplied;
static int id_transparent; static int id_transparent;
static int id_width; static int id_width;
@@ -32,13 +34,15 @@ namespace lime {
if (!init) { if (!init) {
id_b = val_id ("b");
id_bitsPerPixel = val_id ("bitsPerPixel"); id_bitsPerPixel = val_id ("bitsPerPixel");
id_transparent = val_id ("transparent"); id_transparent = val_id ("transparent");
id_buffer = val_id ("buffer"); id_buffer = val_id ("buffer");
id_data = val_id ("data");
id_width = val_id ("width"); id_width = val_id ("width");
id_height = val_id ("height"); id_height = val_id ("height");
id_data = val_id ("data");
id_format = val_id ("format"); id_format = val_id ("format");
id_length = val_id ("length");
id_premultiplied = val_id ("premultiplied"); id_premultiplied = val_id ("premultiplied");
init = true; init = true;
@@ -116,13 +120,14 @@ namespace lime {
if (!init) { if (!init) {
id_b = val_id ("b");
id_bitsPerPixel = val_id ("bitsPerPixel"); id_bitsPerPixel = val_id ("bitsPerPixel");
id_transparent = val_id ("transparent"); id_transparent = val_id ("transparent");
id_buffer = val_id ("buffer"); id_buffer = val_id ("buffer");
id_width = val_id ("width"); id_width = val_id ("width");
id_height = val_id ("height"); id_height = val_id ("height");
id_data = val_id ("data");
id_format = val_id ("format"); id_format = val_id ("format");
id_length = val_id ("length");
id_premultiplied = val_id ("premultiplied"); id_premultiplied = val_id ("premultiplied");
init = true; init = true;
@@ -132,7 +137,8 @@ namespace lime {
alloc_field (mValue, id_width, alloc_int (width)); alloc_field (mValue, id_width, alloc_int (width));
alloc_field (mValue, id_height, alloc_int (height)); alloc_field (mValue, id_height, alloc_int (height));
alloc_field (mValue, id_bitsPerPixel, alloc_int (bitsPerPixel)); alloc_field (mValue, id_bitsPerPixel, alloc_int (bitsPerPixel));
alloc_field (mValue, id_data, data ? data->Value () : alloc_null ()); alloc_field (mValue, id_b, data ? val_field (data->Value (), id_b) : alloc_null ());
alloc_field (mValue, id_length, data ? val_field (data->Value (), id_length) : alloc_null ());
alloc_field (mValue, id_transparent, alloc_bool (transparent)); alloc_field (mValue, id_transparent, alloc_bool (transparent));
alloc_field (mValue, id_format, alloc_int (format)); alloc_field (mValue, id_format, alloc_int (format));
alloc_field (mValue, id_premultiplied, alloc_bool (premultiplied)); alloc_field (mValue, id_premultiplied, alloc_bool (premultiplied));