Fix potential crashes if uses calls terrain tools with invalid params
This commit is contained in:
@@ -285,6 +285,7 @@ bool TerrainTools::GenerateTerrain(Terrain* terrain, const Int2& numberOfPatches
|
||||
|
||||
StringAnsi TerrainTools::SerializePatch(Terrain* terrain, const Int2& patchCoord)
|
||||
{
|
||||
CHECK_RETURN(terrain, StringAnsi::Empty);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, StringAnsi::Empty);
|
||||
|
||||
@@ -300,6 +301,7 @@ StringAnsi TerrainTools::SerializePatch(Terrain* terrain, const Int2& patchCoord
|
||||
|
||||
void TerrainTools::DeserializePatch(Terrain* terrain, const Int2& patchCoord, const StringAnsiView& value)
|
||||
{
|
||||
CHECK(terrain);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK(patch);
|
||||
|
||||
@@ -317,27 +319,31 @@ void TerrainTools::DeserializePatch(Terrain* terrain, const Int2& patchCoord, co
|
||||
|
||||
bool TerrainTools::InitializePatch(Terrain* terrain, const Int2& patchCoord)
|
||||
{
|
||||
CHECK_RETURN(terrain, true);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, true);
|
||||
return patch->InitializeHeightMap();
|
||||
}
|
||||
|
||||
bool TerrainTools::ModifyHeightMap(Terrain* terrain, const Int2& patchCoord, float* samples, const Int2& offset, const Int2& size)
|
||||
bool TerrainTools::ModifyHeightMap(Terrain* terrain, const Int2& patchCoord, const float* samples, const Int2& offset, const Int2& size)
|
||||
{
|
||||
CHECK_RETURN(terrain, true);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, true);
|
||||
return patch->ModifyHeightMap(samples, offset, size);
|
||||
}
|
||||
|
||||
bool TerrainTools::ModifyHolesMask(Terrain* terrain, const Int2& patchCoord, byte* samples, const Int2& offset, const Int2& size)
|
||||
bool TerrainTools::ModifyHolesMask(Terrain* terrain, const Int2& patchCoord, const byte* samples, const Int2& offset, const Int2& size)
|
||||
{
|
||||
CHECK_RETURN(terrain, true);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, true);
|
||||
return patch->ModifyHolesMask(samples, offset, size);
|
||||
}
|
||||
|
||||
bool TerrainTools::ModifySplatMap(Terrain* terrain, const Int2& patchCoord, int32 index, Color32* samples, const Int2& offset, const Int2& size)
|
||||
bool TerrainTools::ModifySplatMap(Terrain* terrain, const Int2& patchCoord, int32 index, const Color32* samples, const Int2& offset, const Int2& size)
|
||||
{
|
||||
CHECK_RETURN(terrain, true);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, true);
|
||||
CHECK_RETURN(index >= 0 && index < TERRAIN_MAX_SPLATMAPS_COUNT, true);
|
||||
@@ -346,6 +352,7 @@ bool TerrainTools::ModifySplatMap(Terrain* terrain, const Int2& patchCoord, int3
|
||||
|
||||
float* TerrainTools::GetHeightmapData(Terrain* terrain, const Int2& patchCoord)
|
||||
{
|
||||
CHECK_RETURN(terrain, nullptr);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, nullptr);
|
||||
return patch->GetHeightmapData();
|
||||
@@ -353,6 +360,7 @@ float* TerrainTools::GetHeightmapData(Terrain* terrain, const Int2& patchCoord)
|
||||
|
||||
byte* TerrainTools::GetHolesMaskData(Terrain* terrain, const Int2& patchCoord)
|
||||
{
|
||||
CHECK_RETURN(terrain, nullptr);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, nullptr);
|
||||
return patch->GetHolesMaskData();
|
||||
@@ -360,6 +368,7 @@ byte* TerrainTools::GetHolesMaskData(Terrain* terrain, const Int2& patchCoord)
|
||||
|
||||
Color32* TerrainTools::GetSplatMapData(Terrain* terrain, const Int2& patchCoord, int32 index)
|
||||
{
|
||||
CHECK_RETURN(terrain, nullptr);
|
||||
auto patch = terrain->GetPatch(patchCoord);
|
||||
CHECK_RETURN(patch, nullptr);
|
||||
return patch->GetSplatMapData(index);
|
||||
|
||||
@@ -68,7 +68,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(TerrainTools);
|
||||
/// <param name="offset">The offset from the first row and column of the heightmap data (offset destination x and z start position).</param>
|
||||
/// <param name="size">The size of the heightmap to modify (x and z). Amount of samples in each direction.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
API_FUNCTION() static bool ModifyHeightMap(Terrain* terrain, API_PARAM(Ref) const Int2& patchCoord, float* samples, API_PARAM(Ref) const Int2& offset, API_PARAM(Ref) const Int2& size);
|
||||
API_FUNCTION() static bool ModifyHeightMap(Terrain* terrain, API_PARAM(Ref) const Int2& patchCoord, const float* samples, API_PARAM(Ref) const Int2& offset, API_PARAM(Ref) const Int2& size);
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the terrain patch holes mask with the given samples.
|
||||
@@ -79,7 +79,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(TerrainTools);
|
||||
/// <param name="offset">The offset from the first row and column of the mask data (offset destination x and z start position).</param>
|
||||
/// <param name="size">The size of the mask to modify (x and z). Amount of samples in each direction.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
API_FUNCTION() static bool ModifyHolesMask(Terrain* terrain, API_PARAM(Ref) const Int2& patchCoord, byte* samples, API_PARAM(Ref) const Int2& offset, API_PARAM(Ref) const Int2& size);
|
||||
API_FUNCTION() static bool ModifyHolesMask(Terrain* terrain, API_PARAM(Ref) const Int2& patchCoord, const byte* samples, API_PARAM(Ref) const Int2& offset, API_PARAM(Ref) const Int2& size);
|
||||
|
||||
/// <summary>
|
||||
/// Modifies the terrain patch splat map (layers mask) with the given samples.
|
||||
@@ -91,7 +91,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(TerrainTools);
|
||||
/// <param name="offset">The offset from the first row and column of the splatmap data (offset destination x and z start position).</param>
|
||||
/// <param name="size">The size of the splatmap to modify (x and z). Amount of samples in each direction.</param>
|
||||
/// <returns>True if failed, otherwise false.</returns>
|
||||
API_FUNCTION() static bool ModifySplatMap(Terrain* terrain, API_PARAM(Ref) const Int2& patchCoord, int32 index, Color32* samples, API_PARAM(Ref) const Int2& offset, API_PARAM(Ref) const Int2& size);
|
||||
API_FUNCTION() static bool ModifySplatMap(Terrain* terrain, API_PARAM(Ref) const Int2& patchCoord, int32 index, const Color32* samples, API_PARAM(Ref) const Int2& offset, API_PARAM(Ref) const Int2& size);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw pointer to the heightmap data (cached internally by the c++ core in editor).
|
||||
|
||||
@@ -1126,12 +1126,9 @@ bool TerrainPatch::InitializeHeightMap()
|
||||
float* TerrainPatch::GetHeightmapData()
|
||||
{
|
||||
PROFILE_CPU_NAMED("Terrain.GetHeightmapData");
|
||||
|
||||
if (_cachedHeightMap.HasItems())
|
||||
return _cachedHeightMap.Get();
|
||||
|
||||
CacheHeightData();
|
||||
|
||||
return _cachedHeightMap.Get();
|
||||
}
|
||||
|
||||
@@ -1144,12 +1141,9 @@ void TerrainPatch::ClearHeightmapCache()
|
||||
byte* TerrainPatch::GetHolesMaskData()
|
||||
{
|
||||
PROFILE_CPU_NAMED("Terrain.GetHolesMaskData");
|
||||
|
||||
if (_cachedHolesMask.HasItems())
|
||||
return _cachedHolesMask.Get();
|
||||
|
||||
CacheHeightData();
|
||||
|
||||
return _cachedHolesMask.Get();
|
||||
}
|
||||
|
||||
@@ -1161,15 +1155,11 @@ void TerrainPatch::ClearHolesMaskCache()
|
||||
|
||||
Color32* TerrainPatch::GetSplatMapData(int32 index)
|
||||
{
|
||||
ASSERT(index >= 0 && index < TERRAIN_MAX_SPLATMAPS_COUNT);
|
||||
|
||||
CHECK_RETURN(index >= 0 && index < TERRAIN_MAX_SPLATMAPS_COUNT, nullptr);
|
||||
PROFILE_CPU_NAMED("Terrain.GetSplatMapData");
|
||||
|
||||
if (_cachedSplatMap[index].HasItems())
|
||||
return _cachedSplatMap[index].Get();
|
||||
|
||||
CacheSplatData();
|
||||
|
||||
return _cachedSplatMap[index].Get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user