I am attempting to create an image using linc’s stb and sdl library together to load an image from memory, instead of directly from a file, using the following code:
public function loadImage(renderer:Renderer, file:String)
{
var bytes = sys.io.File.getBytes(file);
var img = Image.load_from_memory(bytes.getData(), bytes.length);
if (img == null)
{
trace("Error loading image: " + Image.failure_reason());
return;
}
else
{
width = img.w;
height = img.h;
var io:RWops = SDL.RWFromMem(img.bytes, img.bytes.length);
var image:Surface = SDL.loadBMP_RW(io, 1);
if (image == null)
{
trace(SDL.getError());
return;
}
texture = SDL.createTextureFromSurface(renderer, image);
}
}
However, when compiling, on the line where it goes:
var io:RWops = SDL.RWFromMem(img.bytes, img.bytes.length);
I get an error stating that SDL_RWops *SDL_RWFromMem(void *, int) : cannot convert argument 1 from Dynamic to void *
. Strangely, img.bytes
is actually defined in this file as BytesData
which is what RWFromMem
function is asking for.
Any suggestions? Any experts on SDL that can help?