Ran into this where if the user deletes a device like an EQ in renoise, the base reference does not delete properly and remains truthy. Mini tool to demonstrate:
IMPORTANT: Now manually delete the newly added eq from renoise
Hit the shortcut a second time
You will now get a valid oprint() of the device in the terminal, followed by an error in trying to read its display_name property.
The only way around this is to use a pcall to filter these âghost instancesâ out, but my sense is that this is buggy rather than expected?
--global
local dev = nil
---------------------
function main()
---------------------
--song/track
local song = renoise.song()
local track = song.selected_track
if dev == nil then
--insert a new eq 10
dev = track:insert_device_at("Audio/Effects/Native/EQ 10", #track.devices + 1)
return
end
--NOW DELETE THE ADDED EQ MANUALLY IN RENOISE
--"Ghost Reference" Still prints even after device is deleted by user
oprint(dev)
--Errors out!
oprint(dev.display_name)
end
pcall() function needed as a workaround:
--NOTE: dev object will still be valid (truthy) after the device (EQ 10) it points to in renoise
--is deleted by user, however its properties will not so we can test with a pcall to protect from
--an error firing
---------------------------
function pcall_dev(dev)
---------------------------
local ok, result = pcall(function()
return dev.name
end)
--true if dev legitimate, false if not
return ok
end
---
yep, just used here to exit the function avoiding an overarching if/else block like:
if dev == nil then
--insert a new eq 10
dev = track:insert_device_at("Audio/Effects/Native/EQ 10", #track.devices + 1)
else
--NOW DELETE THE ADDED EQ MANUALLY IN RENOISE
--"Ghost Reference" Still prints even after device is deleted by user
oprint(dev)
--Errors out!
oprint(dev.display_name)
end
The Lua user data no longer points to a valid object This is expected and actually can happen with all references to objects that are created within Renoise rather than from Lua.
Unfortunately, we canât magically set such dangling references to nil from within Renoise.
But, we could add a global or member helper function to check whether the object that the Lua wrapper refers still exists.
Iâm not sure how practical this would be. It maybe makes more sense to me to avoid such dangling references, or to keep track of them via notifiers, as martblek mentioned.
the pcall() function does work for this, if used carefully i.e. to catch and not bypass errors, should it be ok for this task?
---------------------------
function pcall_dev(dev)
---------------------------
local ok, result = pcall(function()
return dev.name
end)
--true if dev legitimate, false if not
return ok
end
---