So, I have a simple function that serilizes a string and saves it to a file, and I am getting a C++ runtime error when the code attempts to run
code:
where the function is called
Code: Select all
minetest.register_on_shutdown(function()
main.debug("shutting down") --this line runs
main.save_data_namechange("Savedata", {"string1", "string2"})
end)
Code: Select all
function main.save_data_namechange(name, data)
main.debug("I sure hope this prints") --this line is not run.
if not name then return end
if not data then return end
data_string = minetest.serialize(data)
if not data_string then return end
local file = io.open(main.data_path..name..main.data_ext "w")
if not file then
-- Most likely the data directory doesn't exist, create it
-- and try again.
if minetest.mkdir then
main.debug("the mkdir function is being run")
minetest.mkdir(main.data_path..name..main.data_ext)
else
-- Using os.execute like this is not very platform
-- independent or safe, but most platforms name their
-- directory creation utility mkdir, the data path is
-- unlikely to contain special characters, and the
-- data path is only mutable by the admin.
main.debug("the os function is being run")
os.execute('mkdir "'..main.data_path..name..main.data_ext..'"')
end
file = io.open(main.data_path..name..main.data_ext..id, "w")
if not file then return end--just fail if it can't create directory
end
file:write(data_string)
file:close()
return true
end
Code: Select all
function main.debug(text)
minetest.debug(main.debug_message .. text)
minetest.chat_send_all(main.debug_message .. text)
end
Code: Select all
main.debug_message = "MAIN: "
Code: Select all
Microsoft Visual C++ Rumtime Library
Runtime Error!
Program D:\Minetest\minetest-0.4.15-win64\bin\minetest.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Edit: for anyone with the same question, it crash resulted from passing a table as a parameter during shutdown. I fixed the error by having a static directory that all the data I want saved being placed into, then having the function just save that.