XLua
XLua copied to clipboard
Unsorted scripts leads to fps drops or crash
On projects like Zibomod B737-800X where one module depends (find_dataref) on previous created datarefs if the order of loading modules is (as current) unsorted leads to unexpected behavior that cause crashes or fps drops. All systems (win, lin, mac) are affected, but the problem is more obvious on mac and linux OS, as they don't need/use a hard disk defragment utilily. In windows as long defragment on folder have applied the file pointers are sorted out, so no big problem, but if you modify a file still there is a (big) chance to be unsorted. For more information take a look at Zibo1 and this Zibo2
With a "dirty hack" for testings with following changes in xlua.cpp the problem is fixed !!
void InitScripts(void) {
.
.
struct script {
string m_path {};
string m_init_path {};
string m_script_path {};
};
vector<script> my_scripts;`
.
.
if (strcmp(fptr, ".DS_Store") != 0)
{
string mod_path(scripts_dir_path);
mod_path += "/";
mod_path += fptr;
mod_path += "/";
string script_path(mod_path);
script_path += fptr;
script_path += ".lua";
const script cur_script {mod_path,init_script_path,script_path};
my_scripts.push_back(cur_script);
}
++offset;
if (offset == mf)
break;
}
if (fcount) {
sort(my_scripts.begin(), my_scripts.end(),
[] (script const& a, script const& b){return a.m_path < b.m_path; });
for (auto& cur_script : my_scripts) {
g_modules.push_back(new module(
cur_script.m_path.c_str(),
cur_script.m_init_path.c_str(),
cur_script.m_script_path.c_str(),
lj_alloc_f,
NULL));
}
}
Hi @CrazyKnightGR , thank you for the report. Can you please create a pull request with your changes that we can merge? Thank you!
If you want the 'dirty hack' sure I will do it right now, but for a proper pull you should wait until Wednesday.
I closed it because it only compiles with c++17 or c++23. However, I have confirmation that it solves the problems.