Coverage Report

Created: 2026-04-01 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/Common/scene.cpp
Line
Count
Source
1
/*
2
---------------------------------------------------------------------------
3
Open Asset Import Library (assimp)
4
---------------------------------------------------------------------------
5
6
Copyright (c) 2006-2026, assimp team
7
8
All rights reserved.
9
10
Redistribution and use of this software in source and binary forms,
11
with or without modification, are permitted provided that the following
12
conditions are met:
13
14
* Redistributions of source code must retain the above
15
copyright notice, this list of conditions and the
16
following disclaimer.
17
18
* Redistributions in binary form must reproduce the above
19
copyright notice, this list of conditions and the
20
following disclaimer in the documentation and/or other
21
materials provided with the distribution.
22
23
* Neither the name of the assimp team, nor the names of its
24
contributors may be used to endorse or promote products
25
derived from this software without specific prior
26
written permission of the assimp team.
27
28
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
---------------------------------------------------------------------------
40
*/
41
#include <assimp/scene.h>
42
43
#include "ScenePrivate.h"
44
45
aiScene::aiScene() :
46
12.0k
        mFlags(0),
47
12.0k
        mRootNode(nullptr),
48
12.0k
        mNumMeshes(0),
49
12.0k
        mMeshes(nullptr),
50
12.0k
        mNumMaterials(0),
51
12.0k
        mMaterials(nullptr),
52
12.0k
        mNumAnimations(0),
53
12.0k
        mAnimations(nullptr),
54
12.0k
        mNumTextures(0),
55
12.0k
        mTextures(nullptr),
56
12.0k
        mNumLights(0),
57
12.0k
        mLights(nullptr),
58
12.0k
        mNumCameras(0),
59
12.0k
        mCameras(nullptr),
60
12.0k
        mMetaData(nullptr),
61
12.0k
        mName(),
62
12.0k
        mNumSkeletons(0),
63
12.0k
        mSkeletons(nullptr),
64
12.0k
        mPrivate(new Assimp::ScenePrivateData()) {
65
    // empty
66
12.0k
}
67
68
12.0k
aiScene::~aiScene() {
69
    // delete all sub-objects recursively
70
12.0k
    delete mRootNode;
71
72
    // To make sure we won't crash if the data is invalid it's
73
    // much better to check whether both mNumXXX and mXXX are
74
    // valid instead of relying on just one of them.
75
12.0k
    if (mNumMeshes && mMeshes) {
76
107k
        for (unsigned int a = 0; a < mNumMeshes; ++a) {
77
104k
            delete mMeshes[a];
78
104k
        }
79
3.82k
    }
80
12.0k
    delete[] mMeshes;
81
82
12.0k
    if (mNumMaterials && mMaterials) {
83
15.1k
        for (unsigned int a = 0; a < mNumMaterials; ++a) {
84
10.3k
            delete mMaterials[a];
85
10.3k
        }
86
4.87k
    }
87
12.0k
    delete[] mMaterials;
88
89
12.0k
    if (mNumAnimations && mAnimations) {
90
0
        for (unsigned int a = 0; a < mNumAnimations; ++a) {
91
0
            delete mAnimations[a];
92
0
        }
93
0
    }
94
12.0k
    delete[] mAnimations;
95
96
12.0k
    if (mNumTextures && mTextures) {
97
0
        for (unsigned int a = 0; a < mNumTextures; ++a) {
98
0
            delete mTextures[a];
99
0
        }
100
0
    }
101
12.0k
    delete[] mTextures;
102
103
12.0k
    if (mNumLights && mLights) {
104
0
        for (unsigned int a = 0; a < mNumLights; ++a) {
105
0
            delete mLights[a];
106
0
        }
107
0
    }
108
12.0k
    delete[] mLights;
109
110
12.0k
    if (mNumCameras && mCameras) {
111
0
        for (unsigned int a = 0; a < mNumCameras; ++a) {
112
0
            delete mCameras[a];
113
0
        }
114
0
    }
115
12.0k
    delete[] mCameras;
116
117
12.0k
    aiMetadata::Dealloc(mMetaData);
118
119
12.0k
    delete[] mSkeletons;
120
121
12.0k
    delete static_cast<Assimp::ScenePrivateData *>(mPrivate);
122
12.0k
}
123
124
aiNode::aiNode() :
125
187k
        mName(""),
126
187k
        mParent(nullptr),
127
187k
        mNumChildren(0),
128
187k
        mChildren(nullptr),
129
187k
        mNumMeshes(0),
130
187k
        mMeshes(nullptr),
131
187k
        mMetaData(nullptr) {
132
    // empty
133
187k
}
134
135
aiNode::aiNode(const std::string &name) :
136
0
        mName(name),
137
0
        mParent(nullptr),
138
0
        mNumChildren(0),
139
0
        mChildren(nullptr),
140
0
        mNumMeshes(0),
141
0
        mMeshes(nullptr),
142
0
        mMetaData(nullptr) {
143
    // empty
144
0
}
145
146
/** Destructor */
147
187k
aiNode::~aiNode() {
148
    // delete all children recursively
149
    // to make sure we won't crash if the data is invalid ...
150
187k
    if (mNumChildren && mChildren) {
151
181k
        for (unsigned int a = 0; a < mNumChildren; a++)
152
175k
            delete mChildren[a];
153
5.47k
    }
154
187k
    delete[] mChildren;
155
187k
    delete[] mMeshes;
156
187k
    delete mMetaData;
157
187k
}
158
159
0
const aiNode *aiNode::FindNode(const char *name) const {
160
0
    if (nullptr == name) {
161
0
        return nullptr;
162
0
    }
163
0
    if (!::strcmp(mName.data, name)) {
164
0
        return this;
165
0
    }
166
0
    for (unsigned int i = 0; i < mNumChildren; ++i) {
167
0
        const aiNode *const p = mChildren[i]->FindNode(name);
168
0
        if (p) {
169
0
            return p;
170
0
        }
171
0
    }
172
    // there is definitely no sub-node with this name
173
0
    return nullptr;
174
0
}
175
176
0
aiNode *aiNode::FindNode(const char *name) {
177
0
    if (!::strcmp(mName.data, name)) return this;
178
0
    for (unsigned int i = 0; i < mNumChildren; ++i) {
179
0
        aiNode *const p = mChildren[i]->FindNode(name);
180
0
        if (p) {
181
0
            return p;
182
0
        }
183
0
    }
184
    // there is definitely no sub-node with this name
185
0
    return nullptr;
186
0
}
187
188
0
void aiNode::addChildren(unsigned int numChildren, aiNode **children) {
189
0
    if (nullptr == children || 0 == numChildren) {
190
0
        return;
191
0
    }
192
193
0
    for (unsigned int i = 0; i < numChildren; i++) {
194
0
        aiNode *child = children[i];
195
0
        if (nullptr != child) {
196
0
            child->mParent = this;
197
0
        }
198
0
    }
199
200
0
    if (mNumChildren > 0) {
201
0
        aiNode **tmp = new aiNode *[mNumChildren];
202
0
        ::memcpy(tmp, mChildren, sizeof(aiNode *) * mNumChildren);
203
0
        delete[] mChildren;
204
0
        mChildren = new aiNode *[mNumChildren + numChildren];
205
0
        ::memcpy(mChildren, tmp, sizeof(aiNode *) * mNumChildren);
206
0
        ::memcpy(&mChildren[mNumChildren], children, sizeof(aiNode *) * numChildren);
207
0
        mNumChildren += numChildren;
208
0
        delete[] tmp;
209
0
    } else {
210
0
        mChildren = new aiNode *[numChildren];
211
0
        for (unsigned int i = 0; i < numChildren; i++) {
212
0
            mChildren[i] = children[i];
213
0
        }
214
0
        mNumChildren = numChildren;
215
0
    }
216
0
}