Use ASSERT_NE to check that scene has loaded

EXPECT_NE tries to continue so it ended up dereferencing
null pointers and crashed.
pull/5023/head
Turo Lamminen 2023-03-09 13:38:06 +02:00 committed by Turo Lamminen
parent 6da160f14d
commit 48d89622ee
3 changed files with 19 additions and 19 deletions

View File

@ -190,7 +190,7 @@ private:
Assimp::Importer importer; Assimp::Importer importer;
importer.SetPropertyBool(setting_key, setting_value); importer.SetPropertyBool(setting_key, setting_value);
const aiScene *scene = importer.ReadFile(file_path, aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(file_path, aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
func(scene); func(scene);
} }

View File

@ -61,8 +61,8 @@ public:
void flatShadeTexture() { void flatShadeTexture() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "chrome_sphere.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "chrome_sphere.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
EXPECT_NE(nullptr, scene->mMaterials); ASSERT_NE(nullptr, scene->mMaterials);
aiShadingMode shading_mode = aiShadingMode_Flat; aiShadingMode shading_mode = aiShadingMode_Flat;
scene->mMaterials[0]->Get(AI_MATKEY_SHADING_MODEL, shading_mode); scene->mMaterials[0]->Get(AI_MATKEY_SHADING_MODEL, shading_mode);
@ -74,8 +74,8 @@ public:
void chromeTexture() { void chromeTexture() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "chrome_sphere.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "chrome_sphere.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
EXPECT_NE(nullptr, scene->mMaterials); ASSERT_NE(nullptr, scene->mMaterials);
int chrome; int chrome;
scene->mMaterials[0]->Get(AI_MDL_HL1_MATKEY_CHROME(aiTextureType_DIFFUSE, 0), chrome); scene->mMaterials[0]->Get(AI_MDL_HL1_MATKEY_CHROME(aiTextureType_DIFFUSE, 0), chrome);
@ -87,8 +87,8 @@ public:
void additiveBlendTexture() { void additiveBlendTexture() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "blend_additive.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "blend_additive.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
EXPECT_NE(nullptr, scene->mMaterials); ASSERT_NE(nullptr, scene->mMaterials);
aiBlendMode blend_mode = aiBlendMode_Default; aiBlendMode blend_mode = aiBlendMode_Default;
scene->mMaterials[0]->Get(AI_MATKEY_BLEND_FUNC, blend_mode); scene->mMaterials[0]->Get(AI_MATKEY_BLEND_FUNC, blend_mode);
@ -101,8 +101,8 @@ public:
void textureWithColorMask() { void textureWithColorMask() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "alpha_test.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "alpha_test.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
EXPECT_NE(nullptr, scene->mMaterials); ASSERT_NE(nullptr, scene->mMaterials);
int texture_flags = 0; int texture_flags = 0;
scene->mMaterials[0]->Get(AI_MATKEY_TEXFLAGS_DIFFUSE(0), texture_flags); scene->mMaterials[0]->Get(AI_MATKEY_TEXFLAGS_DIFFUSE(0), texture_flags);

View File

@ -136,7 +136,7 @@ public:
void emptyBonesNames() { void emptyBonesNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_bones.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_bones.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_bones_names = { const StringVector expected_bones_names = {
"Bone", "Bone",
@ -172,7 +172,7 @@ public:
void emptyBodypartsNames() { void emptyBodypartsNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_bodyparts.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_bodyparts.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_bodyparts_names = { const StringVector expected_bodyparts_names = {
"Bodypart", "Bodypart",
@ -209,7 +209,7 @@ public:
void duplicateBodypartsNames() { void duplicateBodypartsNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_bodyparts.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_bodyparts.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_bodyparts_names = { const StringVector expected_bodyparts_names = {
"Bodypart", "Bodypart",
@ -254,7 +254,7 @@ public:
void duplicateSubModelsNames() { void duplicateSubModelsNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_submodels.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_submodels.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const std::vector<StringVector> expected_bodypart_sub_models_names = { const std::vector<StringVector> expected_bodypart_sub_models_names = {
{ {
@ -272,7 +272,7 @@ public:
}; };
const aiNode *bodyparts_node = scene->mRootNode->FindNode(AI_MDL_HL1_NODE_BODYPARTS); const aiNode *bodyparts_node = scene->mRootNode->FindNode(AI_MDL_HL1_NODE_BODYPARTS);
EXPECT_NE(nullptr, bodyparts_node); ASSERT_NE(nullptr, bodyparts_node);
EXPECT_EQ(3u, bodyparts_node->mNumChildren); EXPECT_EQ(3u, bodyparts_node->mNumChildren);
StringVector actual_submodels_names; StringVector actual_submodels_names;
@ -301,7 +301,7 @@ public:
void duplicateSequenceNames() { void duplicateSequenceNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_sequences.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_sequences.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_sequence_names = { const StringVector expected_sequence_names = {
"idle_1", "idle_1",
@ -337,7 +337,7 @@ public:
void emptySequenceNames() { void emptySequenceNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_sequences.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_sequences.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_sequence_names = { const StringVector expected_sequence_names = {
"Sequence", "Sequence",
@ -374,7 +374,7 @@ public:
void duplicateSequenceGroupNames() { void duplicateSequenceGroupNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_sequence_groups/duplicate_sequence_groups.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_sequence_groups/duplicate_sequence_groups.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_sequence_names = { const StringVector expected_sequence_names = {
"default", "default",
@ -412,7 +412,7 @@ public:
void emptySequenceGroupNames() { void emptySequenceGroupNames() {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_sequence_groups/unnamed_sequence_groups.mdl", aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_sequence_groups/unnamed_sequence_groups.mdl", aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
const StringVector expected_sequence_names = { const StringVector expected_sequence_names = {
"default", "default",
@ -440,7 +440,7 @@ public:
Assimp::Importer importer; Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(MDL_HL1_FILE_MAN, aiProcess_ValidateDataStructure); const aiScene *scene = importer.ReadFile(MDL_HL1_FILE_MAN, aiProcess_ValidateDataStructure);
EXPECT_NE(nullptr, scene); ASSERT_NE(nullptr, scene);
aiNode *scene_bones_node = scene->mRootNode->FindNode(AI_MDL_HL1_NODE_BONES); aiNode *scene_bones_node = scene->mRootNode->FindNode(AI_MDL_HL1_NODE_BONES);