Abort on big map

This commit is contained in:
Miloslav Ciz 2025-06-12 20:49:10 +02:00
parent 74013219e5
commit c317f84582
4 changed files with 20 additions and 15 deletions

19
map.h
View file

@ -301,16 +301,16 @@ uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord)
/**
Adds given block to current map, including possibly deleting a block by
adding LCR_BLOCK_NONE. The function handles sorting the block to the right
position.
position. Returns 1 if successful, else 0.
*/
void _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
uint8_t _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
{
LCR_LOG2("adding map block");
if (LCR_currentMap.blockCount >= LCR_SETTING_MAP_MAX_BLOCKS)
{
LCR_LOG0("couldn't add block");
return;
return 0;
}
uint32_t coord = LCR_mapBlockGetCoordNumber(block);
@ -336,7 +336,7 @@ void _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
LCR_currentMap.blockCount--;
}
return;
return 1;
}
if (insertAt == LCR_currentMap.blockCount ||
@ -358,6 +358,8 @@ void _LCR_mapAddBlock(const uint8_t block[LCR_BLOCK_SIZE])
for (uint8_t j = 0; j < LCR_BLOCK_SIZE; ++j)
LCR_currentMap.blocks[insertAt + j] = block[j];
return 1;
}
/**
@ -627,7 +629,8 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name)
{
LCR_makeMapBlock(type,x2,y2,z2,mat,t2,tmpBlock);
_LCR_mapAddBlock(tmpBlock);
if (!_LCR_mapAddBlock(tmpBlock))
return 0;
}
}
}
@ -660,7 +663,8 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name)
LCR_makeMapBlock(prevBlock[0],x + i,y + j,z + k,mat,transform,
tmpBlock);
_LCR_mapAddBlock(tmpBlock);
if (!_LCR_mapAddBlock(tmpBlock))
return 0;
}
break;
@ -709,7 +713,8 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name)
LCR_makeMapBlock(block,coords[0],coords[1],coords[2],mat,trans,
prevBlock);
_LCR_mapAddBlock(prevBlock);
if (!_LCR_mapAddBlock(prevBlock))
return 0;
break;
}