mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix /emergeblocks crashing in debug builds (#11461)
The reason for the bug was an u16 overflow, thus failing the assert. This only happened in Debug build but not in Release builds.
This commit is contained in:
parent
0257e7150f
commit
e7cd4cfa25
5 changed files with 29 additions and 24 deletions
|
@ -165,20 +165,17 @@ EmergeManager::EmergeManager(Server *server)
|
|||
if (nthreads < 1)
|
||||
nthreads = 1;
|
||||
|
||||
m_qlimit_total = g_settings->getU16("emergequeue_limit_total");
|
||||
m_qlimit_total = g_settings->getU32("emergequeue_limit_total");
|
||||
// FIXME: these fallback values are probably not good
|
||||
if (!g_settings->getU16NoEx("emergequeue_limit_diskonly", m_qlimit_diskonly))
|
||||
if (!g_settings->getU32NoEx("emergequeue_limit_diskonly", m_qlimit_diskonly))
|
||||
m_qlimit_diskonly = nthreads * 5 + 1;
|
||||
if (!g_settings->getU16NoEx("emergequeue_limit_generate", m_qlimit_generate))
|
||||
if (!g_settings->getU32NoEx("emergequeue_limit_generate", m_qlimit_generate))
|
||||
m_qlimit_generate = nthreads + 1;
|
||||
|
||||
// don't trust user input for something very important like this
|
||||
if (m_qlimit_total < 1)
|
||||
m_qlimit_total = 1;
|
||||
if (m_qlimit_diskonly < 1)
|
||||
m_qlimit_diskonly = 1;
|
||||
if (m_qlimit_generate < 1)
|
||||
m_qlimit_generate = 1;
|
||||
m_qlimit_total = rangelim(m_qlimit_total, 1, 1000000);
|
||||
m_qlimit_diskonly = rangelim(m_qlimit_diskonly, 1, 1000000);
|
||||
m_qlimit_generate = rangelim(m_qlimit_generate, 1, 1000000);
|
||||
|
||||
for (s16 i = 0; i < nthreads; i++)
|
||||
m_threads.push_back(new EmergeThread(server, i));
|
||||
|
@ -425,14 +422,14 @@ bool EmergeManager::pushBlockEmergeData(
|
|||
void *callback_param,
|
||||
bool *entry_already_exists)
|
||||
{
|
||||
u16 &count_peer = m_peer_queue_count[peer_requested];
|
||||
u32 &count_peer = m_peer_queue_count[peer_requested];
|
||||
|
||||
if ((flags & BLOCK_EMERGE_FORCE_QUEUE) == 0) {
|
||||
if (m_blocks_enqueued.size() >= m_qlimit_total)
|
||||
return false;
|
||||
|
||||
if (peer_requested != PEER_ID_INEXISTENT) {
|
||||
u16 qlimit_peer = (flags & BLOCK_EMERGE_ALLOW_GEN) ?
|
||||
u32 qlimit_peer = (flags & BLOCK_EMERGE_ALLOW_GEN) ?
|
||||
m_qlimit_generate : m_qlimit_diskonly;
|
||||
if (count_peer >= qlimit_peer)
|
||||
return false;
|
||||
|
@ -467,20 +464,18 @@ bool EmergeManager::pushBlockEmergeData(
|
|||
|
||||
bool EmergeManager::popBlockEmergeData(v3s16 pos, BlockEmergeData *bedata)
|
||||
{
|
||||
std::map<v3s16, BlockEmergeData>::iterator it;
|
||||
std::unordered_map<u16, u16>::iterator it2;
|
||||
|
||||
it = m_blocks_enqueued.find(pos);
|
||||
auto it = m_blocks_enqueued.find(pos);
|
||||
if (it == m_blocks_enqueued.end())
|
||||
return false;
|
||||
|
||||
*bedata = it->second;
|
||||
|
||||
it2 = m_peer_queue_count.find(bedata->peer_requested);
|
||||
auto it2 = m_peer_queue_count.find(bedata->peer_requested);
|
||||
if (it2 == m_peer_queue_count.end())
|
||||
return false;
|
||||
|
||||
u16 &count_peer = it2->second;
|
||||
u32 &count_peer = it2->second;
|
||||
|
||||
assert(count_peer != 0);
|
||||
count_peer--;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue