mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Fix non-integer coordinates passed to ImageData:mapPixel/setPixel/getPixel and SoundData:set/getSample.
LuaJIT does interesting things when you index into a FFI array using a non-integer value.
This commit is contained in:
@@ -35,6 +35,7 @@ local status, ffi = pcall(require, "ffi")
|
||||
if not status then return end
|
||||
|
||||
local tonumber, assert, error = tonumber, assert, error
|
||||
local floor = math.floor
|
||||
|
||||
local float = ffi.typeof("float")
|
||||
local datatypes = {ffi.typeof("uint8_t *"), ffi.typeof("int16_t *")}
|
||||
@@ -77,6 +78,8 @@ local objectcache = setmetatable({}, {
|
||||
function SoundData:getSample(i)
|
||||
if type(i) ~= "number" then error("bad argument #1 to SoundData:getSample (expected number)", 2) end
|
||||
|
||||
i = floor(i)
|
||||
|
||||
local p = objectcache[self]
|
||||
|
||||
if not (i >= 0 and i < p.size/p.bytedepth) then
|
||||
@@ -96,6 +99,8 @@ function SoundData:setSample(i, sample)
|
||||
if type(i) ~= "number" then error("bad argument #1 to SoundData:setSample (expected number)", 2) end
|
||||
if type(sample) ~= "number" then error("bad argument #2 to SoundData:setSample (expected number)", 2) end
|
||||
|
||||
i = floor(i)
|
||||
|
||||
local p = objectcache[self]
|
||||
|
||||
if not (i >= 0 and i < p.size/p.bytedepth) then
|
||||
|
||||
Reference in New Issue
Block a user