Skip to content

Commit 9e82e17

Browse files
committed
prevent crash from bam files
1 parent c39ef34 commit 9e82e17

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

panda/src/text/geomTextGlyph.cxx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ GeomTextGlyph(DynamicTextGlyph *glyph, const GeomVertexData *data) :
3939
// Initially, there is only one glyph in the Geom. There might be
4040
// additional Glyphs later when we flatten the graph and call
4141
// Geom::unify().
42-
_glyphs.reserve(1);
43-
_glyphs.push_back(glyph);
4442
if (glyph != (DynamicTextGlyph *)NULL) {
43+
_glyphs.reserve(1);
44+
_glyphs.push_back(glyph);
4545
glyph->_geom_count++;
4646
}
4747
}
@@ -58,7 +58,9 @@ GeomTextGlyph(const GeomTextGlyph &copy) :
5858
{
5959
Glyphs::iterator gi;
6060
for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
61-
(*gi)->_geom_count++;
61+
DynamicTextGlyph *glyph = (*gi);
62+
nassertv(glyph != (DynamicTextGlyph *)NULL);
63+
glyph->_geom_count++;
6264
}
6365
}
6466

@@ -73,12 +75,16 @@ operator = (const GeomTextGlyph &copy) {
7375

7476
Glyphs::iterator gi;
7577
for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
76-
(*gi)->_geom_count--;
78+
DynamicTextGlyph *glyph = (*gi);
79+
nassertv(glyph != (DynamicTextGlyph *)NULL);
80+
glyph->_geom_count--;
7781
nassertv((*gi)->_geom_count >= 0);
7882
}
7983
_glyphs = copy._glyphs;
8084
for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
81-
(*gi)->_geom_count++;
85+
DynamicTextGlyph *glyph = (*gi);
86+
nassertv(glyph != (DynamicTextGlyph *)NULL);
87+
glyph->_geom_count++;
8288
}
8389
}
8490

@@ -91,8 +97,10 @@ GeomTextGlyph::
9197
~GeomTextGlyph() {
9298
Glyphs::iterator gi;
9399
for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
94-
(*gi)->_geom_count--;
95-
nassertv((*gi)->_geom_count >= 0);
100+
DynamicTextGlyph *glyph = (*gi);
101+
nassertv(glyph != (DynamicTextGlyph *)NULL);
102+
glyph->_geom_count--;
103+
nassertv(glyph->_geom_count >= 0);
96104
}
97105
}
98106

@@ -153,7 +161,9 @@ output(ostream &out) const {
153161
out << ", glyphs: [";
154162
Glyphs::const_iterator gi;
155163
for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
156-
out << " " << (*gi)->get_character();
164+
DynamicTextGlyph *glyph = (*gi);
165+
nassertv(glyph != (DynamicTextGlyph *)NULL);
166+
out << " " << glyph->get_character();
157167
}
158168
out << " ]";
159169
}
@@ -170,7 +180,9 @@ write(ostream &out, int indent_level) const {
170180
<< "Glyphs: [";
171181
Glyphs::const_iterator gi;
172182
for (gi = _glyphs.begin(); gi != _glyphs.end(); ++gi) {
173-
out << " " << (*gi)->get_character();
183+
DynamicTextGlyph *glyph = (*gi);
184+
nassertv(glyph != (DynamicTextGlyph *)NULL);
185+
out << " " << glyph->get_character();
174186
}
175187
out << " ]\n";
176188
}

0 commit comments

Comments
 (0)