Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEBUG] Try Catch and log GetCell crash #4187

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions Source/ACE.Server/Entity/PositionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,50 +78,61 @@ public static Position FromGlobal(this Position p, Vector3 pos)
/// </summary>
public static uint GetCell(this Position p)
{
var landblock = LScape.get_landblock(p.LandblockId.Raw);

// dungeons
// TODO: investigate dungeons that are below actual traversable overworld terrain
// ex., 010AFFFF
//if (landblock.IsDungeon)
if (p.Indoors)
return GetIndoorCell(p);
try
{
//var landblock = LScape.get_landblock(p.LandblockId.Raw);

// outside - could be on landscape, in building, or underground cave
var cellID = GetOutdoorCell(p);
var landcell = LScape.get_landcell(cellID) as LandCell;
// dungeons
// TODO: investigate dungeons that are below actual traversable overworld terrain
// ex., 010AFFFF
//if (landblock.IsDungeon)
if (p.Indoors)
return GetIndoorCell(p);

if (landcell == null)
return cellID;
// outside - could be on landscape, in building, or underground cave
var cellID = GetOutdoorCell(p);
var landcell = LScape.get_landcell(cellID) as LandCell;

if (landcell.has_building())
{
var envCells = landcell.Building.get_building_cells();
foreach (var envCell in envCells)
if (envCell.point_in_cell(p.Pos))
return envCell.ID;
}
if (landcell == null)
return cellID;

// handle underground areas ie. caves
// get the terrain Z-height for this X/Y
Physics.Polygon walkable = null;
var terrainPoly = landcell.find_terrain_poly(p.Pos, ref walkable);
if (walkable != null)
{
Vector3 terrainPos = p.Pos;
walkable.Plane.set_height(ref terrainPos);

// are we below ground? if so, search all of the indoor cells for this landblock
if (terrainPos.Z > p.Pos.Z)
if (landcell.has_building())
{
var envCells = landblock.get_envcells();
var envCells = landcell.Building.get_building_cells();
foreach (var envCell in envCells)
if (envCell.point_in_cell(p.Pos))
return envCell.ID;
}

// handle underground areas ie. caves
// get the terrain Z-height for this X/Y
Physics.Polygon walkable = null;
var terrainPoly = landcell.find_terrain_poly(p.Pos, ref walkable);
if (walkable != null)
{
Vector3 terrainPos = p.Pos;
walkable.Plane.set_height(ref terrainPos);

// are we below ground? if so, search all of the indoor cells for this landblock
if (terrainPos.Z > p.Pos.Z)
{
var landblock = LScape.get_landblock(p.LandblockId.Raw);
var envCells = landblock.get_envcells();
foreach (var envCell in envCells)
if (envCell.point_in_cell(p.Pos))
return envCell.ID;
}
}

return cellID;
}
catch (Exception e)
{
log.ErrorFormat("GetCell() threw an exception: {0}\nposition as LOC => {1}", e.ToString(), p.ToLOCString());
log.Error(e);

return cellID;
return 0;
}
}

/// <summary>
Expand Down