Some checks failed
release / linux/x86_64 (pull_request) Failing after 1m54s
release / freebsd/x86_64 (pull_request) Successful in 5m1s
release / linux/aarch64 (pull_request) Failing after 1m54s
release / linux/armv7 (pull_request) Failing after 2m12s
release / linux/i686 (pull_request) Failing after 1m59s
release / android (pull_request) Successful in 2m54s
release / windows/i686 (pull_request) Successful in 2m3s
release / windows/x86_64 (pull_request) Successful in 2m15s
62 lines
1.9 KiB
Lua
62 lines
1.9 KiB
Lua
-- 08: pinned textures (shapes texture, material maps) stay alive while pinned,
|
|
-- and the pins are dropped when the owning object is released.
|
|
local M = dofile("tests/helpers.lua")
|
|
local ffi = require("ffi")
|
|
local R = M.load()
|
|
|
|
if not M.window(64, 64) then
|
|
M.skip("08_pins", "no window")
|
|
return
|
|
end
|
|
|
|
M.reset()
|
|
local b = M.snapshot()
|
|
|
|
local img = R.GenImageColor(2, 2, R.WHITE)
|
|
|
|
-- (a) shapes texture pin
|
|
local tex = R.LoadTextureFromImage(img)
|
|
local tex_id = tex.id
|
|
M.ok(tex_id ~= 0, "shapes texture created")
|
|
local tex_copy = ffi.new("Texture2D[1]", tex)
|
|
M.eq(tex_copy[0].id, tex_id, "saved raw texture copy")
|
|
|
|
R.SetShapesTexture(tex, ffi.new("Rectangle", 0, 0, 1, 1))
|
|
|
|
tex = nil
|
|
M.gc(3)
|
|
M.eq(M.delta(b, "released"), 0, "pinned shapes texture was not collected")
|
|
local shape = R.GetShapesTexture()
|
|
M.ok(shape.id ~= 0, "shapes texture is installed")
|
|
M.eq(shape.id, tex_id, "installed shapes texture is the pinned one")
|
|
|
|
-- Explicit unload of the saved copy must restore the previous shapes texture
|
|
-- and not crash. (The original cdata is the one held by the pin.)
|
|
R.UnloadTexture(tex_copy[0])
|
|
M.ok(R.GetShapesTexture().id ~= tex_id, "previous shapes texture restored")
|
|
|
|
-- (b) material map pin
|
|
local mat = R.LoadMaterialDefault()
|
|
M.ok(mat.maps ~= nil, "default material has maps")
|
|
local tex2 = R.LoadTextureFromImage(img)
|
|
local tex2_id = tex2.id
|
|
R.SetMaterialTexture(mat, R.MATERIAL_MAP_DIFFUSE, tex2)
|
|
M.eq(mat.maps[R.MATERIAL_MAP_DIFFUSE].texture.id, tex2_id,
|
|
"material map references the texture")
|
|
|
|
tex2 = nil
|
|
M.gc(3)
|
|
M.ok(mat.maps[R.MATERIAL_MAP_DIFFUSE].texture.id ~= 0,
|
|
"material pin kept the map texture alive")
|
|
M.eq(mat.maps[R.MATERIAL_MAP_DIFFUSE].texture.id, tex2_id,
|
|
"material map still points at the pinned texture")
|
|
|
|
R.UnloadMaterial(mat)
|
|
mat = nil
|
|
-- Pins are dropped with the material; the texture can now go away.
|
|
M.gc(3)
|
|
|
|
R.UnloadImage(img)
|
|
M.eq(M.delta(b, "errors"), 0, "no finalizer errors")
|
|
|
|
print("ok 08_pins")
|