Skip to content

Commit 2fa046a

Browse files
author
Chris Conway
committed
Upgraded validation to only assert in packaged and instead log error and bail while in editor.
1 parent 563c33d commit 2fa046a

2 files changed

Lines changed: 63 additions & 49 deletions

File tree

Source/Private/RuntimeMeshComponent.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ void URuntimeMeshComponent::UpdateMeshSectionPositionsImmediate(int32 SectionInd
727727
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSectionPositionsImmediate);
728728

729729
// Validate all update parameters
730-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
730+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
731731

732732
// Get section
733733
RuntimeMeshSectionPtr& Section = MeshSections[SectionIndex];
@@ -766,7 +766,7 @@ void URuntimeMeshComponent::UpdateMeshSectionPositionsImmediate(int32 SectionInd
766766
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSectionPositionsImmediate_WithBoundinBox);
767767

768768
// Validate all update parameters
769-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
769+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
770770

771771
// Get section
772772
RuntimeMeshSectionPtr& Section = MeshSections[SectionIndex];
@@ -804,7 +804,7 @@ void URuntimeMeshComponent::UpdateMeshSectionPositionsImmediate(int32 SectionInd
804804
TArray<FVector>* URuntimeMeshComponent::BeginMeshSectionPositionUpdate(int32 SectionIndex)
805805
{
806806
// Validate all update parameters
807-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
807+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, nullptr);
808808

809809
// Get section
810810
RuntimeMeshSectionPtr& Section = MeshSections[SectionIndex];
@@ -815,7 +815,7 @@ TArray<FVector>* URuntimeMeshComponent::BeginMeshSectionPositionUpdate(int32 Sec
815815
void URuntimeMeshComponent::EndMeshSectionPositionUpdate(int32 SectionIndex)
816816
{
817817
// Validate all update parameters
818-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
818+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
819819

820820
// TODO: Validate that the position buffer is still the same length
821821

@@ -825,7 +825,7 @@ void URuntimeMeshComponent::EndMeshSectionPositionUpdate(int32 SectionIndex)
825825
void URuntimeMeshComponent::EndMeshSectionPositionUpdate(int32 SectionIndex, const FBox& BoundingBox)
826826
{
827827
// Validate all update parameters
828-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
828+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
829829

830830
RuntimeMeshSectionPtr& Section = MeshSections[SectionIndex];
831831

@@ -853,7 +853,7 @@ void URuntimeMeshComponent::CreateMeshSection(int32 SectionIndex, const TArray<F
853853
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSection);
854854

855855
// Validate all creation parameters
856-
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles);
856+
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, /*VoidReturn*/);
857857

858858
// Create the section
859859
auto NewSection = CreateOrResetSectionInternalType(SectionIndex, 1, false);
@@ -879,7 +879,7 @@ void URuntimeMeshComponent::CreateMeshSection(int32 SectionIndex, const TArray<F
879879
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSection_DualUV);
880880

881881
// Validate all creation parameters
882-
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles);
882+
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, /*VoidReturn*/);
883883

884884
// Create the section
885885
auto NewSection = CreateOrResetSectionInternalType(SectionIndex, 2, false);
@@ -918,7 +918,7 @@ void URuntimeMeshComponent::UpdateMeshSection(int32 SectionIndex, const TArray<F
918918
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection);
919919

920920
// Validate all update parameters
921-
RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex);
921+
RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex, /*VoidReturn*/);
922922

923923
// Validate section type
924924
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<FRuntimeMeshVertex<1>>();
@@ -946,7 +946,7 @@ void URuntimeMeshComponent::UpdateMeshSection(int32 SectionIndex, const TArray<F
946946
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_DualUV);
947947

948948
// Validate all update parameters
949-
RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex);
949+
RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex, /*VoidReturn*/);
950950

951951
// Validate section type
952952
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<FRuntimeMeshVertex<2>>();

Source/Public/RuntimeMeshComponent.h

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,43 @@
99
#include "PhysicsEngine/ConvexElem.h"
1010
#include "RuntimeMeshComponent.generated.h"
1111

12-
#define RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles) \
13-
check(SectionIndex >= 0 && "SectionIndex cannot be negative."); \
14-
check(Vertices.Num() > 0 && "Vertices length must not be 0."); \
15-
check(Triangles.Num() > 0 && "Triangles length must not be 0");
16-
17-
#define RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, Vertices, Triangles, Positions) \
18-
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles) \
19-
check((Positions.Num() == Vertices.Num()) && "Positions must be the same length as Vertices");
20-
21-
#define RMC_VALIDATE_BOUNDINGBOX(BoundingBox) \
22-
check(BoundingBox.IsValid && "BoundingBox must be valid.");
23-
24-
#define RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex) \
25-
check(SectionIndex >= 0 && "SectionIndex cannot be negative."); \
26-
check(SectionIndex < MeshSections.Num() && MeshSections[SectionIndex].IsValid() && "Invalid SectionIndex.");
27-
28-
#define RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex) \
29-
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex) \
30-
check(MeshSections[SectionIndex]->bIsInternalSectionType && "Section is not of legacy type.");
12+
// This set of macros is only meant for argument validation as it will return out of whatever scope.
13+
#if WITH_EDITOR
14+
#define RMC_CHECKINGAME_LOGINEDITOR(Condition, Message, RetVal) \
15+
{ if (!(Condition)) \
16+
{ \
17+
Log(TEXT(Message), true); \
18+
return RetVal; \
19+
} }
20+
#else
21+
#define RMC_CHECKINGAME_LOGINEDITOR(Condition, Message, RetVal) \
22+
check(Condition && Message);
23+
#endif
24+
25+
26+
#define RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, RetVal) \
27+
RMC_CHECKINGAME_LOGINEDITOR((SectionIndex >= 0), "SectionIndex cannot be negative.", RetVal); \
28+
RMC_CHECKINGAME_LOGINEDITOR((Vertices.Num() > 0), "Vertices length must not be 0.", RetVal); \
29+
RMC_CHECKINGAME_LOGINEDITOR((Triangles.Num() > 0), "Triangles length must not be 0", RetVal);
30+
31+
#define RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, Vertices, Triangles, Positions, RetVal) \
32+
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, RetVal) \
33+
RMC_CHECKINGAME_LOGINEDITOR((Positions.Num() == Vertices.Num()), "Positions must be the same length as Vertices", RetVal);
34+
35+
#define RMC_VALIDATE_BOUNDINGBOX(BoundingBox, RetVal) \
36+
RMC_CHECKINGAME_LOGINEDITOR(BoundingBox.IsValid, "BoundingBox must be valid.", RetVal);
37+
38+
#define RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, RetVal) \
39+
RMC_CHECKINGAME_LOGINEDITOR((SectionIndex >= 0), "SectionIndex cannot be negative.", RetVal); \
40+
RMC_CHECKINGAME_LOGINEDITOR((SectionIndex < MeshSections.Num() && MeshSections[SectionIndex].IsValid()), "Invalid SectionIndex.", RetVal);
41+
42+
#define RMC_VALIDATE_UPDATEPARAMETERS_INTERNALSECTION(SectionIndex, RetVal) \
43+
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, RetVal) \
44+
RMC_CHECKINGAME_LOGINEDITOR((MeshSections[SectionIndex]->bIsInternalSectionType), "Section is not of legacy type.", RetVal);
3145

32-
#define RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex) \
33-
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex) \
34-
check(MeshSections[SectionIndex]->IsDualBufferSection() && "Section is not dual buffer.");
46+
#define RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, RetVal) \
47+
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, RetVal) \
48+
RMC_CHECKINGAME_LOGINEDITOR((MeshSections[SectionIndex]->IsDualBufferSection()), "Section is not dual buffer.", RetVal);
3549

3650

3751

@@ -139,7 +153,7 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
139153
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSection_VertexType);
140154

141155
// Validate all creation parameters
142-
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles);
156+
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, /*VoidReturn*/);
143157

144158
// Create the section
145159
TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, false);
@@ -174,8 +188,8 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
174188
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSection_VertexType_WithBoundingBox);
175189

176190
// Validate all creation parameters
177-
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles);
178-
RMC_VALIDATE_BOUNDINGBOX(BoundingBox);
191+
RMC_VALIDATE_CREATIONPARAMETERS(SectionIndex, Vertices, Triangles, /*VoidReturn*/);
192+
RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
179193

180194
// Create the section
181195
TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, false);
@@ -210,7 +224,7 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
210224
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSectionDualBuffer_VertexType);
211225

212226
// Validate all creation parameters
213-
RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, VertexData, Triangles, VertexPositions);
227+
RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, VertexData, Triangles, VertexPositions, /*VoidReturn*/);
214228

215229
TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, true);
216230

@@ -245,8 +259,8 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
245259
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_CreateMeshSectionDualBuffer_VertexType_WithBoundingBox);
246260

247261
// Validate all creation parameters
248-
RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, VertexData, Triangles, VertexPositions);
249-
RMC_VALIDATE_BOUNDINGBOX(BoundingBox);
262+
RMC_VALIDATE_CREATIONPARAMETERS_DUALBUFFER(SectionIndex, VertexData, Triangles, VertexPositions, /*VoidReturn*/);
263+
RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
250264

251265
TSharedPtr<FRuntimeMeshSection<VertexType>> Section = CreateOrResetSection<FRuntimeMeshSection<VertexType>>(SectionIndex, true);
252266

@@ -275,7 +289,7 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
275289
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType);
276290

277291
// Validate all update parameters
278-
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex);
292+
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
279293

280294
// Validate section type
281295
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -325,8 +339,8 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
325339
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType_WithBoundingBox);
326340

327341
// Validate all update parameters
328-
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex);
329-
RMC_VALIDATE_BOUNDINGBOX(BoundingBox);
342+
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
343+
RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
330344

331345
// Validate section type
332346
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -376,7 +390,7 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
376390
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType_WithTriangles);
377391

378392
// Validate all update parameters
379-
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex);
393+
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
380394

381395
// Validate section type
382396
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -439,8 +453,8 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
439453
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_VertexType_WithTrianglesAndBoundinBox);
440454

441455
// Validate all update parameters
442-
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex);
443-
RMC_VALIDATE_BOUNDINGBOX(BoundingBox);
456+
RMC_VALIDATE_UPDATEPARAMETERS(SectionIndex, /*VoidReturn*/);
457+
RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
444458

445459
// Validate section type
446460
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -503,7 +517,7 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
503517
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType);
504518

505519
// Validate all update parameters
506-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
520+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
507521

508522
// Validate section type
509523
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -568,8 +582,8 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
568582
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType_WithBoundingBox);
569583

570584
// Validate all update parameters
571-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
572-
RMC_VALIDATE_BOUNDINGBOX(BoundingBox);
585+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
586+
RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
573587

574588
// Validate section type
575589
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -634,7 +648,7 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
634648
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType_WithTriangles);
635649

636650
// Validate all update parameters
637-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
651+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
638652

639653
// Validate section type
640654
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();
@@ -712,8 +726,8 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu
712726
SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_UpdateMeshSection_Dual_VertexType_WithTrianglesAndBoundinBox);
713727

714728
// Validate all update parameters
715-
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex);
716-
RMC_VALIDATE_BOUNDINGBOX(BoundingBox);
729+
RMC_VALIDATE_UPDATEPARAMETERS_DUALBUFFER(SectionIndex, /*VoidReturn*/);
730+
RMC_VALIDATE_BOUNDINGBOX(BoundingBox, /*VoidReturn*/);
717731

718732
// Validate section type
719733
MeshSections[SectionIndex]->GetVertexType()->EnsureEquals<VertexType>();

0 commit comments

Comments
 (0)