Coverage Report

Created: 2026-09-14 07:44

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
269k
        mFlags(0),
47
269k
        mRootNode(nullptr),
48
269k
        mNumMeshes(0),
49
269k
        mMeshes(nullptr),
50
269k
        mNumMaterials(0),
51
269k
        mMaterials(nullptr),
52
269k
        mNumAnimations(0),
53
269k
        mAnimations(nullptr),
54
269k
        mNumTextures(0),
55
269k
        mTextures(nullptr),
56
269k
        mNumLights(0),
57
269k
        mLights(nullptr),
58
269k
        mNumCameras(0),
59
269k
        mCameras(nullptr),
60
269k
        mMetaData(nullptr),
61
269k
        mName(),
62
269k
        mNumSkeletons(0),
63
269k
        mSkeletons(nullptr),
64
269k
        mPrivate(new Assimp::ScenePrivateData()) {
65
    // empty
66
269k
}
67
68
269k
aiScene::~aiScene() {
69
    // delete all sub-objects recursively
70
269k
    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
269k
    if (mNumMeshes && mMeshes) {
76
2.03M
        for (unsigned int a = 0; a < mNumMeshes; ++a) {
77
1.88M
            delete mMeshes[a];
78
1.88M
        }
79
153k
    }
80
269k
    delete[] mMeshes;
81
82
269k
    if (mNumMaterials && mMaterials) {
83
347k
        for (unsigned int a = 0; a < mNumMaterials; ++a) {
84
191k
            delete mMaterials[a];
85
191k
        }
86
156k
    }
87
269k
    delete[] mMaterials;
88
89
269k
    if (mNumAnimations && mAnimations) {
90
35.7k
        for (unsigned int a = 0; a < mNumAnimations; ++a) {
91
21.4k
            delete mAnimations[a];
92
21.4k
        }
93
14.2k
    }
94
269k
    delete[] mAnimations;
95
96
269k
    if (mNumTextures && mTextures) {
97
22.3k
        for (unsigned int a = 0; a < mNumTextures; ++a) {
98
12.7k
            delete mTextures[a];
99
12.7k
        }
100
9.59k
    }
101
269k
    delete[] mTextures;
102
103
269k
    if (mNumLights && mLights) {
104
42.9k
        for (unsigned int a = 0; a < mNumLights; ++a) {
105
38.7k
            delete mLights[a];
106
38.7k
        }
107
4.11k
    }
108
269k
    delete[] mLights;
109
110
269k
    if (mNumCameras && mCameras) {
111
28.0k
        for (unsigned int a = 0; a < mNumCameras; ++a) {
112
21.3k
            delete mCameras[a];
113
21.3k
        }
114
6.69k
    }
115
269k
    delete[] mCameras;
116
117
269k
    aiMetadata::Dealloc(mMetaData);
118
119
269k
    delete[] mSkeletons;
120
121
269k
    delete static_cast<Assimp::ScenePrivateData *>(mPrivate);
122
269k
}
123
124
aiNode::aiNode() :
125
7.11M
        mName(""),
126
7.11M
        mParent(nullptr),
127
7.11M
        mNumChildren(0),
128
7.11M
        mChildren(nullptr),
129
7.11M
        mNumMeshes(0),
130
7.11M
        mMeshes(nullptr),
131
7.11M
        mMetaData(nullptr) {
132
    // empty
133
7.11M
}
134
135
aiNode::aiNode(const std::string &name) :
136
58.0k
        mName(name),
137
58.0k
        mParent(nullptr),
138
58.0k
        mNumChildren(0),
139
58.0k
        mChildren(nullptr),
140
58.0k
        mNumMeshes(0),
141
58.0k
        mMeshes(nullptr),
142
58.0k
        mMetaData(nullptr) {
143
    // empty
144
58.0k
}
145
146
/** Destructor */
147
7.16M
aiNode::~aiNode() {
148
    // delete all children recursively
149
    // to make sure we won't crash if the data is invalid ...
150
7.16M
    if (mNumChildren && mChildren) {
151
7.44M
        for (unsigned int a = 0; a < mNumChildren; a++)
152
6.81M
            delete mChildren[a];
153
622k
    }
154
7.16M
    delete[] mChildren;
155
7.16M
    delete[] mMeshes;
156
7.16M
    delete mMetaData;
157
7.16M
}
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
3.99M
aiNode *aiNode::FindNode(const char *name) {
177
3.99M
    if (!::strcmp(mName.data, name)) return this;
178
7.18M
    for (unsigned int i = 0; i < mNumChildren; ++i) {
179
3.41M
        aiNode *const p = mChildren[i]->FindNode(name);
180
3.41M
        if (p) {
181
77.1k
            return p;
182
77.1k
        }
183
3.41M
    }
184
    // there is definitely no sub-node with this name
185
3.77M
    return nullptr;
186
3.84M
}
187
188
2.01k
void aiNode::addChildren(unsigned int numChildren, aiNode **children) {
189
2.01k
    if (nullptr == children || 0 == numChildren) {
190
0
        return;
191
0
    }
192
193
5.66k
    for (unsigned int i = 0; i < numChildren; i++) {
194
3.64k
        aiNode *child = children[i];
195
3.64k
        if (nullptr != child) {
196
3.64k
            child->mParent = this;
197
3.64k
        }
198
3.64k
    }
199
200
2.01k
    if (mNumChildren > 0) {
201
1.38k
        aiNode **tmp = new aiNode *[mNumChildren];
202
1.38k
        ::memcpy(tmp, mChildren, sizeof(aiNode *) * mNumChildren);
203
1.38k
        delete[] mChildren;
204
1.38k
        mChildren = new aiNode *[mNumChildren + numChildren];
205
1.38k
        ::memcpy(mChildren, tmp, sizeof(aiNode *) * mNumChildren);
206
1.38k
        ::memcpy(&mChildren[mNumChildren], children, sizeof(aiNode *) * numChildren);
207
1.38k
        mNumChildren += numChildren;
208
1.38k
        delete[] tmp;
209
1.38k
    } else {
210
631
        mChildren = new aiNode *[numChildren];
211
2.88k
        for (unsigned int i = 0; i < numChildren; i++) {
212
2.25k
            mChildren[i] = children[i];
213
2.25k
        }
214
631
        mNumChildren = numChildren;
215
631
    }
216
2.01k
}