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
45 lines
1.4 KiB
Lua
45 lines
1.4 KiB
Lua
-- 04: LoadModelFromMesh consumes the mesh; unloading the model releases it
|
|
-- once, and a saved (zeroed) mesh copy is a harmless no-op.
|
|
local M = dofile("tests/helpers.lua")
|
|
local ffi = require("ffi")
|
|
local R = M.load()
|
|
|
|
if not M.window(64, 64) then
|
|
M.skip("04_model_from_mesh", "no window")
|
|
return
|
|
end
|
|
|
|
M.reset()
|
|
local b = M.snapshot()
|
|
|
|
local mesh = R.GenMeshCube(1, 1, 1)
|
|
M.ok(mesh.vertexCount > 0, "cube mesh built")
|
|
|
|
local model = R.LoadModelFromMesh(mesh)
|
|
M.eq(model.meshCount, 1, "model has one mesh")
|
|
M.ok(model.meshes[0].vertexCount > 0, "model mesh is valid")
|
|
if R.IsModelReady ~= nil then
|
|
M.ok(R.IsModelReady(model), "model is ready")
|
|
end
|
|
|
|
-- Ownership moved to the model: the mesh was disarmed and zeroed.
|
|
M.ok(mesh.vertices == nil,
|
|
"mesh was consumed (vertices cleared) by LoadModelFromMesh")
|
|
local mesh_copy = ffi.new("Mesh[1]", mesh)
|
|
|
|
mesh = nil
|
|
M.gc(3)
|
|
M.eq(M.delta(b, "released"), 0, "consumed mesh was not released separately")
|
|
M.eq(M.delta(b, "errors"), 0, "no finalizer errors before unload")
|
|
|
|
R.UnloadModel(model)
|
|
M.eq(M.delta(b, "released"), 1, "UnloadModel released exactly once")
|
|
|
|
-- A saved copy of the (zeroed) mesh must be a no-op, not a crash/double free.
|
|
R.UnloadMesh(mesh_copy[0])
|
|
M.eq(M.delta(b, "errors"), 0, "saved mesh copy raised no errors")
|
|
M.ok(M.delta(b, "released") <= 2,
|
|
"saved mesh copy did not free the model's mesh again")
|
|
M.eq(M.delta(b, "errors"), 0, "no finalizer errors")
|
|
|
|
print("ok 04_model_from_mesh")
|