general: use nassert_raise instead of nassertv(false) et al

Even a brief error message in the assertion is infinitely more useful to a user who is not at home in the source code, especially for assertions that may reasonably be triggered by honest user mistakes.
This commit is contained in:
rdb 2018-11-28 17:35:20 +01:00
parent 594e6b394b
commit 97d4e32a06
45 changed files with 108 additions and 79 deletions

View File

@ -1240,7 +1240,7 @@ shadow_inherited_field(const string &name) {
}
// If we get here, the named field wasn't in the list. Huh.
nassertv(false);
nassert_raise("named field not in list");
}
/**

View File

@ -110,7 +110,7 @@ out(NotifySeverity severity, bool prefix) const {
nout << *this << "(" << severity << "): ";
}
if (assert_abort) {
nassertr(false, nout);
nassert_raise("unprotected debug statement");
}
return nout;

View File

@ -239,7 +239,7 @@ set_table(char table_id, const CPTA_stdfloat &table) {
if (table.size() > 1 && (int)table.size() < num_frames) {
// The new table has an invalid number of frames--it doesn't match the
// bundle's requirement.
nassertv(false);
nassert_raise("mismatched number of frames");
return;
}

View File

@ -104,7 +104,7 @@ set_table(const CPTA_stdfloat &table) {
if (table.size() > 1 && (int)table.size() < num_frames) {
// The new table has an invalid number of frames--it doesn't match the
// bundle's requirement.
nassertv(false);
nassert_raise("mismatched number of frames");
return;
}

View File

@ -743,7 +743,7 @@ issue_timer_query(int pstats_index) {
*/
void GraphicsStateGuardian::
dispatch_compute(int num_groups_x, int num_groups_y, int num_groups_z) {
nassertv(false /* Compute shaders not supported by GSG */);
nassert_raise("Compute shaders not supported by GSG");
}
/**

View File

@ -192,7 +192,8 @@ write(ostream &out, int indent_level) const {
default:
// invalid group type
nassertv(false);
nassert_raise("invalid EggGroup type");
return;
}
if (is_of_type(EggBin::get_class_type())) {

View File

@ -445,7 +445,8 @@ add_vertex(EggVertex *vertex, int index) {
}
// Oops, you duplicated a vertex index.
nassertr(false, nullptr);
nassert_raise("duplicate vertex index");
return nullptr;
}
_unique_vertices.insert(vertex);

View File

@ -142,7 +142,8 @@ get_value(int row, LMatrix4d &mat) const {
default:
// The contents string contained an invalid letter.
nassertv(false);
nassert_raise("invalid letter in contents string");
return;
}
}

View File

@ -368,7 +368,8 @@ get_value(int row, LMatrix4d &mat) const {
default:
// One of the child tables had an invalid name.
nassertv(false);
nassert_raise("invalid name in child table");
return;
}
}
}

View File

@ -298,7 +298,7 @@ wake_task(AsyncTask *task) {
return;
default:
nassertv(false);
nassert_raise("unexpected task state");
return;
}
}

View File

@ -29,7 +29,7 @@ output(std::ostream &out) const {
*/
void PointerEvent::
write_datagram(Datagram &dg) const {
nassertv(false && "This function not implemented yet.");
nassert_raise("This function not implemented yet.");
}
/**
@ -37,5 +37,5 @@ write_datagram(Datagram &dg) const {
*/
void PointerEvent::
read_datagram(DatagramIterator &scan) {
nassertv(false && "This function not implemented yet.");
nassert_raise("This function not implemented yet.");
}

View File

@ -32,7 +32,7 @@ get_display_list(GLuint &index, const CLP(GeomMunger) *munger,
UpdateSeq modified) {
#if defined(OPENGLES) || !defined(SUPPORT_FIXED_FUNCTION)
// Display lists not supported by OpenGL ES.
nassertr(false, false);
nassert_raise("OpenGL ES does not support display lists");
return false;
#else

View File

@ -14144,7 +14144,7 @@ extract_texture_image(PTA_uchar &image, size_t &page_size,
Texture::ComponentType type,
Texture::CompressionMode compression, int n) {
#ifdef OPENGLES // Extracting texture data unsupported in OpenGL ES.
nassertr(false, false);
nassert_raise("OpenGL ES does not support extracting texture data");
return false;
#else

View File

@ -1504,7 +1504,7 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) {
} else {
// If this assertion fails, clear_prepared() was given a prepared_objects
// that the geom didn't know about.
nassertv(false);
nassert_raise("unknown PreparedGraphicsObjects");
}
}

View File

@ -47,7 +47,7 @@ GeomCacheManager() :
GeomCacheManager::
~GeomCacheManager() {
// Shouldn't be deleting this global object.
nassertv(false);
nassert_raise("attempt to delete GeomCacheManager");
}
/**

View File

@ -221,7 +221,7 @@ add_vertex(int vertex) {
((uint32_t *)ptr)[num_rows] = vertex;
break;
default:
nassertv(false);
nassert_raise("unsupported index type");
break;
}
}
@ -1510,7 +1510,7 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) {
} else {
// If this assertion fails, clear_prepared() was given a prepared_objects
// which the data array didn't know about.
nassertv(false);
nassert_raise("unknown PreparedGraphicsObjects");
}
}
@ -2230,7 +2230,7 @@ get_vertex(int i) const {
return ((uint32_t *)ptr)[i];
break;
default:
nassertr(false, -1);
nassert_raise("unsupported index type");
return -1;
}
@ -2296,7 +2296,7 @@ get_referenced_vertices(BitArray &bits) const {
}
break;
default:
nassertv(false);
nassert_raise("unsupported index type");
break;
}
} else {

View File

@ -139,7 +139,7 @@ CPT(GeomVertexArrayData) GeomTrifans::
rotate_impl() const {
// Actually, we can't rotate fans without chaging the winding order. It's
// an error to define a flat shade model for a GeomTrifan.
nassertr(false, nullptr);
nassert_raise("GeomTrifans cannot have flat shading model");
return nullptr;
}

View File

@ -351,7 +351,7 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) {
} else {
// If this assertion fails, clear_prepared() was given a prepared_objects
// which the data array didn't know about.
nassertv(false);
nassert_raise("unknown PreparedGraphicsObjects");
}
}

View File

@ -1121,7 +1121,8 @@ do_set_color(GeomVertexData *vdata, const LColor &color) {
const GeomVertexColumn *column;
int array_index;
if (!format->get_array_info(InternalName::get_color(), array_index, column)) {
nassertv(false);
nassert_raise("no color column");
return;
}
size_t stride = format->get_array(array_index)->get_stride();

View File

@ -3705,7 +3705,7 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) {
} else {
// If this assertion fails, clear_prepared() was given a prepared_objects
// which the texture didn't know about.
nassertv(false);
nassert_raise("unknown PreparedGraphicsObjects");
}
}

View File

@ -4897,8 +4897,8 @@ do_read_ktx(CData *cdata, istream &in, const string &filename, bool header_only)
}
break;
default:
nassertr(false, false);
break;
nassert_raise("unexpected channel count");
return false;
}
}
@ -6591,8 +6591,9 @@ do_reconsider_image_properties(CData *cdata, int x_size, int y_size, int num_com
default:
// Eh?
nassertr(false, false);
nassert_raise("unexpected channel count");
cdata->_format = F_rgb;
return false;
}
}
@ -7989,7 +7990,8 @@ convert_from_pfm(PTA_uchar &image, size_t page_size, int z,
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
return;
}
nassertv((unsigned char *)p == &image[idx] + page_size);
@ -8199,7 +8201,8 @@ convert_to_pfm(PfmFile &pfm, int x_size, int y_size,
break;
default:
nassertr(false, false);
nassert_raise("unexpected channel count");
return false;
}
nassertr((unsigned char *)p == &image[idx] + page_size, false);

View File

@ -54,7 +54,7 @@ set_default_gsg(GraphicsStateGuardianBase *default_gsg) {
LightMutexHolder holder(gsg_list->_lock);
if (find(gsg_list->_gsgs.begin(), gsg_list->_gsgs.end(), default_gsg) == gsg_list->_gsgs.end()) {
// The specified GSG doesn't exist or it has already destructed.
nassertv(false);
nassert_raise("GSG not found or already destructed");
return;
}

View File

@ -43,7 +43,7 @@ Socket_Address(const struct sockaddr &inaddr) {
_addr6 = (const sockaddr_in6 &)inaddr;
} else {
nassertv(false);
nassert_raise("unsupported address family");
clear();
}
}
@ -106,7 +106,7 @@ operator == (const Socket_Address &in) const {
}
// Unsupported address family.
nassertr(false, false);
nassert_raise("unsupported address family");
return false;
}
@ -224,7 +224,7 @@ operator < (const Socket_Address &in) const {
}
// Unsupported address family.
nassertr(false, false);
nassert_raise("unsupported address family");
return false;
}

View File

@ -98,7 +98,7 @@ get_ip() const {
getnameinfo(&_addr, sizeof(sockaddr_in6), buf, sizeof(buf), nullptr, 0, NI_NUMERICHOST);
} else {
nassertr(false, std::string());
nassert_raise("unsupported address family");
}
return std::string(buf);
@ -124,7 +124,7 @@ get_ip_port() const {
sprintf(buf + strlen(buf), "]:%hu", get_port());
} else {
nassertr(false, std::string());
nassert_raise("unsupported address family");
}
return std::string(buf);

View File

@ -478,7 +478,8 @@ check_send_error(bool okflag) {
if (!okflag) {
static ConfigVariableBool abort_send_error("abort-send-error", false);
if (abort_send_error) {
nassertr(false, false);
nassert_raise("send error");
return false;
}
// Assume any error means the connection has been reset; tell our manager

View File

@ -46,7 +46,8 @@ DatagramTCPHeader(const NetDatagram &datagram, int header_size) {
break;
default:
nassertv(false);
nassert_raise("invalid header size");
return;
}
nassertv((int)_header.get_length() == header_size);

View File

@ -276,7 +276,7 @@ get_timewarp_curve(int n) const {
n--;
}
}
nassertr(false, nullptr);
nassert_raise("index out of range");
return nullptr;
}

View File

@ -72,7 +72,7 @@ make(ClipPlaneAttrib::Operation op, PlaneNode *plane) {
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}
@ -110,7 +110,7 @@ make(ClipPlaneAttrib::Operation op, PlaneNode *plane1, PlaneNode *plane2) {
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}
@ -152,7 +152,7 @@ make(ClipPlaneAttrib::Operation op, PlaneNode *plane1, PlaneNode *plane2,
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}
@ -197,7 +197,7 @@ make(ClipPlaneAttrib::Operation op, PlaneNode *plane1, PlaneNode *plane2,
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}

View File

@ -199,7 +199,7 @@ make_new_bin(int bin_index, GraphicsStateGuardianBase *gsg,
}
// Hmm, unknown (or unregistered) bin type.
nassertr(false, nullptr);
nassert_raise("unknown bin type");
return nullptr;
}

View File

@ -116,7 +116,7 @@ make(LightAttrib::Operation op, Light *light) {
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}
@ -154,7 +154,7 @@ make(LightAttrib::Operation op, Light *light1, Light *light2) {
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}
@ -196,7 +196,7 @@ make(LightAttrib::Operation op, Light *light1, Light *light2,
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}
@ -241,7 +241,7 @@ make(LightAttrib::Operation op, Light *light1, Light *light2,
return attrib;
}
nassertr(false, make());
nassert_raise("invalid operation");
return make();
}

View File

@ -718,7 +718,8 @@ get_state(const NodePath &other, Thread *current_thread) const {
} else {
pgraph_cat.error()
<< *this << " is not related to " << other << "\n";
nassertr(false, RenderState::make_empty());
nassert_raise("unrelated nodes");
return RenderState::make_empty();
}
}
@ -792,7 +793,8 @@ get_transform(const NodePath &other, Thread *current_thread) const {
} else {
pgraph_cat.error()
<< *this << " is not related to " << other << "\n";
nassertr(false, TransformState::make_identity());
nassert_raise("unrelated nodes");
return TransformState::make_identity();
}
}
@ -877,7 +879,8 @@ get_prev_transform(const NodePath &other, Thread *current_thread) const {
} else {
pgraph_cat.error()
<< *this << " is not related to " << other << "\n";
nassertr(false, TransformState::make_identity());
nassert_raise("unrelated nodes");
return TransformState::make_identity();
}
}

View File

@ -2383,7 +2383,8 @@ r_copy_subgraph(PandaNode::InstanceMap &inst_map, Thread *current_thread) const
<< "Don't know how to copy nodes of type " << get_type() << "\n";
if (no_unsupported_copy) {
nassertr(false, nullptr);
nassert_raise("unsupported copy");
return nullptr;
}
}

View File

@ -78,7 +78,7 @@ register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib) {
pgraph_cat->error()
<< "Too many registered RenderAttribs; not registering "
<< type_handle << "\n";
nassertr(false, 0);
nassert_raise("out of RenderAttrib slots");
return 0;
}

View File

@ -333,7 +333,8 @@ r_apply_attribs(PandaNode *node, const AccumulatedAttribs &attribs,
<< child_node->get_type() << "\n";
if (no_unsupported_copy) {
nassertv(false);
nassert_raise("unsupported copy");
return;
}
resist_copy = true;

View File

@ -85,7 +85,7 @@ void AmbientLight::
bind(GraphicsStateGuardianBase *, const NodePath &, int) {
// AmbientLights aren't bound to light id's; this function should never be
// called.
nassertv(false);
nassert_raise("cannot bind AmbientLight");
}
/**

View File

@ -161,7 +161,8 @@ call_python_func(PyObject *function, PyObject *args) {
#ifndef HAVE_THREADS
// Shouldn't be possible to come here without having some kind of
// threading support enabled.
nassertr(false, nullptr);
nassert_raise("threading support disabled");
return nullptr;
#else
#ifdef SIMPLE_THREADS

View File

@ -346,7 +346,8 @@ load(const PNMImage &pnmimage) {
break;
default:
nassertr(false, false);
nassert_raise("unexpected channel count");
return false;
}
return true;
}
@ -410,7 +411,8 @@ store(PNMImage &pnmimage) const {
break;
default:
nassertr(false, false);
nassert_raise("unexpected channel count");
return false;
}
return true;
}
@ -877,7 +879,8 @@ set_no_data_nan(int num_channels) {
_has_point = has_point_nan_4;
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
break;
}
} else {
clear_no_data_value();
@ -909,7 +912,8 @@ set_no_data_value(const LPoint4f &no_data_value) {
_has_point = has_point_4;
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
break;
}
}
@ -938,7 +942,8 @@ set_no_data_threshold(const LPoint4f &no_data_value) {
_has_point = has_point_threshold_4;
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
break;
}
}
@ -1121,7 +1126,8 @@ quick_filter_from(const PfmFile &from) {
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
return;
}
new_data.push_back(0.0);
@ -1826,7 +1832,8 @@ compute_planar_bounds(const LPoint2f &center, PN_float32 point_dist, PN_float32
break;
default:
nassertr(false, nullptr);
nassert_raise("invalid coordinate system");
return nullptr;
}
// Rotate the bounding volume back into the original space of the screen.
@ -1879,7 +1886,8 @@ compute_sample_point(LPoint3f &result,
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
break;
}
}

View File

@ -596,8 +596,8 @@ set_color_space(ColorSpace color_space) {
break;
default:
nassertv(false);
break;
nassert_raise("invalid color space");
return;
}
// Initialize the new encoding settings.
@ -852,7 +852,7 @@ get_channel_val(int x, int y, int channel) const {
pnmimage_cat.error()
<< "Invalid request for channel " << channel << " in "
<< get_num_channels() << "-channel image.\n";
nassertr(false, 0);
nassert_raise("unexpected channel count");
return 0;
}
}
@ -888,7 +888,8 @@ set_channel_val(int x, int y, int channel, xelval value) {
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
break;
}
}
@ -918,7 +919,7 @@ get_channel(int x, int y, int channel) const {
pnmimage_cat.error()
<< "Invalid request for channel " << channel << " in "
<< get_num_channels() << "-channel image.\n";
nassertr(false, 0);
nassert_raise("unexpected channel count");
return 0;
}
}
@ -954,7 +955,8 @@ set_channel(int x, int y, int channel, float value) {
break;
default:
nassertv(false);
nassert_raise("unexpected channel count");
break;
}
}
@ -2126,7 +2128,7 @@ setup_encoding() {
break;
default:
nassertv(false);
nassert_raise("invalid color space");
break;
}
} else {
@ -2153,7 +2155,7 @@ setup_encoding() {
break;
default:
nassertv(false);
nassert_raise("invalid color space");
break;
}
}

View File

@ -283,7 +283,8 @@ write_pfm(const PfmFile &pfm) {
break;
default:
nassertr(false, false);
nassert_raise("unexpected channel count");
return false;
}
(*_file) << pfm.get_x_size() << " " << pfm.get_y_size() << "\n";

View File

@ -135,7 +135,8 @@ write_header() {
break;
default:
nassertr(false, false);
nassert_raise("unexpected channel count");
return false;
}
// For some reason, we have problems with SGI image files whose pixmax value

View File

@ -93,7 +93,7 @@ has_max_num_bits() {
*/
INLINE int SparseArray::
get_max_num_bits() {
nassertr(false, 0);
nassert_raise("SparseArray has no maximum bit count");
return 0;
}

View File

@ -2536,7 +2536,7 @@ get_primitive(TypeHandle prim_type) {
return _points;
}
nassertr(false, nullptr);
nassert_raise("unexpected primitive type");
return nullptr;
}

View File

@ -487,7 +487,8 @@ fetch_buffer() {
block[i + 2] = ex;
}
#else
nassertr(false /* Not compiled with JPEG support*/, nullptr);
nassert_raise("JPEG support not compiled-in");
return nullptr;
#endif
break;
}

View File

@ -79,7 +79,7 @@ Open(const char *file, const char *mode) {
return new PandaIOStream(*stream);
} else {
nassertr(false, nullptr); // Not implemented on purpose.
nassert_raise("write mode not implemented");
return nullptr;
}
}

View File

@ -40,7 +40,7 @@ get_frame_rate() const {
void EggBackPointer::
extend_to(int num_frames) {
// Whoops, can't extend this kind of table!
nassertv(false);
nassert_raise("can't extend this kind of table");
}
/**