Tool crashes Renoise using Document load

Trying to implement default values for a DocumentList element in preferences and able to crash Renoise with

Fatal Error: Failed to create an object of type ‘TLuaDocumentListImpl’ ( Fatal error while reading a document. Failed to create an object of type ‘path’! ).

A fatal error or crash occured (unhandled exception in thread: GUI).

The code looks like this:

renoise.Document.create("Entry") {
  name = renoise.Document.ObservableString(),
  path = renoise.Document.ObservableString(),
}

function create_entry(name, path)
  local entry = renoise.Document.instantiate("Entry")
  entry.name.value = name
  entry.path.value = path
  return entry
end

local default_list = renoise.Document.DocumentList()

for i = 1, 8 do
  default_list:insert(create_entry("some name", "abc"))
end

renoise.Document.create("MyPreferences") {
  list = default_list
}

local preferences = renoise.Document.instantiate("MyPreferences")
renoise.tool().preferences = preferences

BTW, can we somehow make this work apart from the crash using the “defaults way” instead of modifying preferences.list after load if it doesn’t contain enough elements?

1 Like

Thanks. Will fix the crash.

You can initialize the content after the preferences got assigned. Check if it’s empty to figure out if it’s the default.

renoise.Document.create("Entry") {
  name = renoise.Document.ObservableString(),
  path = renoise.Document.ObservableString(),
}
 
function create_entry(name, path)
  local entry = renoise.Document.instantiate("Entry")
  entry.name.value = name
  entry.path.value = path
  return entry
end

renoise.Document.create("MyPreferences") {
  list = renoise.Document.DocumentList()
}

local preferences = renoise.Document.instantiate("MyPreferences")
renoise.tool().preferences = preferences

if #preferences.list == 0 then
  for i = 1, 8 do
    preferences.list:insert(create_entry("some name", "abc"))
  end
end

This whole document stuff is pretty hard to get. Mentioned this a few times. Should get rid of it completely or rewrite it from scratch in some major API update.

1 Like

Please don’t. I really enjoy it for loading/dumping the whole state of a tool directly from/to its structure. It’s very convenient whenever using tool_data.

There is a similar (?) crash when doing this that has to be circumvented. XML nodes that auto-create lua classes can easily crash depending on what the __init function does. I always go around this by an “if args” expression, to determine if the object was auto-created from xml or manually created by the user. Maybe it’s only slightly related to the topic, but I thought it best to mention it…

1 Like

When loading a document there can be no arguments. So this is expected. But Renoise should not crash here but only the tool when it does not handle the nil arguments?

i’m really trying to use this to make sense of this dynamic view script i have going, but no matter what i do, it keeps overwriting the preferences.xml for no reason. it’s really difficult going and i’m about to give up. i have no idea what i’m doing wrong, incessantly.

preferences = renoise.Document.create("ScriptingToolPreferences") {
...............
................
   PakettiDynamicViews = renoise.Document.DocumentList(),
}

then
PakettiDynamicViews.lua (27.2 KB)

and i just can’t for the life of me figure out why it keeps overwriting preferences.xml instead of safely saving and loading.

i’ve been trying to do this fixing on&off for multiple weeks.