diff --git a/Source/Editor/Tools/Terrain/TerrainTools.cpp b/Source/Editor/Tools/Terrain/TerrainTools.cpp index 545e60d54..89d0aa17d 100644 --- a/Source/Editor/Tools/Terrain/TerrainTools.cpp +++ b/Source/Editor/Tools/Terrain/TerrainTools.cpp @@ -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); diff --git a/Source/Editor/Tools/Terrain/TerrainTools.h b/Source/Editor/Tools/Terrain/TerrainTools.h index 6f4682bf6..bb35c45c9 100644 --- a/Source/Editor/Tools/Terrain/TerrainTools.h +++ b/Source/Editor/Tools/Terrain/TerrainTools.h @@ -68,7 +68,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(TerrainTools); /// The offset from the first row and column of the heightmap data (offset destination x and z start position). /// The size of the heightmap to modify (x and z). Amount of samples in each direction. /// True if failed, otherwise false. - 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); /// /// Modifies the terrain patch holes mask with the given samples. @@ -79,7 +79,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(TerrainTools); /// The offset from the first row and column of the mask data (offset destination x and z start position). /// The size of the mask to modify (x and z). Amount of samples in each direction. /// True if failed, otherwise false. - 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); /// /// Modifies the terrain patch splat map (layers mask) with the given samples. @@ -91,7 +91,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(TerrainTools); /// The offset from the first row and column of the splatmap data (offset destination x and z start position). /// The size of the splatmap to modify (x and z). Amount of samples in each direction. /// True if failed, otherwise false. - 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); /// /// Gets the raw pointer to the heightmap data (cached internally by the c++ core in editor). diff --git a/Source/Engine/Terrain/TerrainPatch.cpp b/Source/Engine/Terrain/TerrainPatch.cpp index 92a8c09d3..8e05062c8 100644 --- a/Source/Engine/Terrain/TerrainPatch.cpp +++ b/Source/Engine/Terrain/TerrainPatch.cpp @@ -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(); }