Don't divide by zero when hints.ini has no hints

HintDatabase::init() picks a random hint with rand() % the number of
loaded hints. When hints.ini is empty or can't be read, that number is
zero and the app crashes at startup. get_hint() already returns nothing
in that case, but only after init() has run.

Ported from Snapmaker/OrcaSlicer@05acbec702

Co-authored-by: fire2wind <1229725087@qq.com>
This commit is contained in:
Ian Bassiandfire2wind committed 2026-11-30 14:12:40 -03:00
1 parent abe2fba75c
commit dc9ef93046
1 file changed
+4
+4
View File
@@ -339,6 +339,10 @@ void HintDatabase::init()
}
void HintDatabase::init_random_hint_id()
{
if (m_loaded_hints.empty()) {
m_hint_id = 0;
return;
}
srand(time(NULL));
m_hint_id = rand() % m_loaded_hints.size();
}