From ca39e47dc650e60bff54a8d276d8f7126ad1a5df Mon Sep 17 00:00:00 2001 From: panikon Date: Tue, 22 Jul 2014 16:54:38 -0300 Subject: Fixed some issues with CELL_NOSTACK - Crashing issue when loading maps using map cache (issue: 8270) http://hercules.ws/board/tracker/issue-8270-enable-cell-nostack-crash/ - Counter was not being decrease correctly when leaving a cell Merged map_addblcell and map_delblcell --- src/map/map.c | 58 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'src/map/map.c') diff --git a/src/map/map.c b/src/map/map.c index a89478cb1..b254b6792 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -167,31 +167,32 @@ int map_freeblock_timer(int tid, int64 tick, int id, intptr_t data) { return 0; } -/*========================================== - * These pair of functions update the counter of how many objects - * lie on a tile. - *------------------------------------------*/ -void map_addblcell(struct block_list *bl) { +/** + * Updates the counter (cell.cell_bl) of how many objects are on a tile. + * @param add Whether the counter should be increased or decreased + **/ +void map_update_cell_bl( struct block_list *bl, bool increase ) { #ifdef CELL_NOSTACK + int pos; + if( bl->m < 0 || bl->x < 0 || bl->x >= map->list[bl->m].xs || bl->y < 0 || bl->y >= map->list[bl->m].ys || !(bl->type&BL_CHAR) ) return; - map->list[bl->m].cell[bl->x+bl->y*map->list[bl->m].xs].cell_bl++; -#else - return; -#endif -} -void map_delblcell(struct block_list *bl) { -#ifdef CELL_NOSTACK - if( bl->m < 0 || bl->x < 0 || bl->x >= map->list[bl->m].xs - || bl->y < 0 || bl->y >= map->list[bl->m].ys - || !(bl->type&BL_CHAR) ) - map->list[bl->m].cell[bl->x+bl->y*map->list[bl->m].xs].cell_bl--; -#else - return; + // When reading from mapcache the cell isn't initialized + // TODO: Maybe start initializing cells when they're loaded instead of + // having to get them here? [Panikon] + if( map->list[bl->m].cell == (struct mapcell *)0xdeadbeaf ) + map->cellfromcache(&map->list[bl->m]); + + pos = bl->x + bl->y*map->list[bl->m].xs; + if( increase ) + map->list[bl->m].cell[pos].cell_bl++; + else + map->list[bl->m].cell[pos].cell_bl--; #endif + return; } /*========================================== @@ -237,7 +238,7 @@ int map_addblock(struct block_list* bl) } #ifdef CELL_NOSTACK - map->addblcell(bl); + map->update_cell_bl(bl, true); #endif return 0; @@ -261,7 +262,7 @@ int map_delblock(struct block_list* bl) } #ifdef CELL_NOSTACK - map->delblcell(bl); + map->update_cell_bl(bl, false); #endif pos = bl->x/BLOCK_SIZE+(bl->y/BLOCK_SIZE)*map->list[bl->m].bxs; @@ -319,13 +320,13 @@ int map_moveblock(struct block_list *bl, int x1, int y1, int64 tick) { if (moveblock) map->delblock(bl); #ifdef CELL_NOSTACK - else map->delblcell(bl); + else map->update_cell_bl(bl, false); #endif bl->x = x1; bl->y = y1; if (moveblock) map->addblock(bl); #ifdef CELL_NOSTACK - else map->addblcell(bl); + else map->update_cell_bl(bl, true); #endif if (bl->type&BL_CHAR) { @@ -2521,8 +2522,13 @@ void map_cellfromcache(struct map_data *m) { decode_zip(decode_buffer, &size, m->cellPos+sizeof(struct map_cache_map_info), info->len); CREATE(m->cell, struct mapcell, size); - for( xy = 0; xy < size; ++xy ) + // Set cell properties + for( xy = 0; xy < size; ++xy ) { m->cell[xy] = map->gat2cell(decode_buffer[xy]); +#ifdef CELL_NOSTACK + m->cell[xy].cell_bl = 0; +#endif + } m->getcellp = map->getcellp; m->setcell = map->setcell; @@ -3293,6 +3299,9 @@ int map_readgat (struct map_data* m) type = 3; // Cell is 0 (walkable) but under water level, set to 3 (walkable water) m->cell[xy] = map->gat2cell(type); +#ifdef CELL_NOSTACK + m->cell[xy].cell_bl = 0; +#endif } aFree(gat); @@ -6126,8 +6135,7 @@ void map_defaults(void) { map->versionscreen = map_versionscreen; map->arg_next_value = map_arg_next_value; - map->addblcell = map_addblcell; - map->delblcell = map_delblcell; + map->update_cell_bl = map_update_cell_bl; map->get_new_bonus_id = map_get_new_bonus_id; -- cgit v1.2.3-60-g2f50