diff --git a/raylib/src/core/texture.rs b/raylib/src/core/texture.rs index 082b8c73..3e145c4e 100644 --- a/raylib/src/core/texture.rs +++ b/raylib/src/core/texture.rs @@ -3,6 +3,7 @@ use crate::core::color::Color; use crate::core::math::{Rectangle, Vector4}; use crate::core::{RaylibHandle, RaylibThread}; use crate::ffi; +use std::convert::TryInto; use std::ffi::CString; use std::mem::ManuallyDrop; @@ -693,12 +694,18 @@ impl Image { Ok(Image(i)) } - /// Loads image from a given memory buffer as a vector of arrays - /// ensure filetype is extension, for example, ".png" - pub fn load_image_from_mem(filetype: &str, bytes: &Vec, size: i32) -> Result { + /// Loads image from a given memory buffer + /// The input data is expected to be in a supported file format such as png. Which formats are + /// supported depend on the build flags used for the raylib (C) library. + pub fn load_image_from_mem(filetype: &str, bytes: &[u8]) -> Result { let c_filetype = CString::new(filetype).unwrap(); - let c_bytes = bytes.as_ptr(); - let i = unsafe { ffi::LoadImageFromMemory(c_filetype.as_ptr(), c_bytes, size) }; + let i = unsafe { + ffi::LoadImageFromMemory( + c_filetype.as_ptr(), + bytes.as_ptr(), + bytes.len().try_into().unwrap(), + ) + }; if i.data.is_null() { return Err(format!( "Image data is null. Check provided buffer data"