From 11d34600478bff2cb5f6c9abcb3522acf49429fa Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 23 Sep 2002 18:27:05 +0000 Subject: [PATCH] better assertion checking --- direct/src/interval/cInterval.I | 12 ++++++------ direct/src/interval/cInterval.cxx | 17 +++++++++-------- direct/src/interval/cInterval.h | 4 ++-- direct/src/interval/cLerpAnimEffectInterval.cxx | 2 +- direct/src/interval/cLerpNodePathInterval.cxx | 10 +++++----- direct/src/interval/cMetaInterval.cxx | 13 +++++++------ direct/src/interval/hideInterval.cxx | 4 ++++ direct/src/interval/showInterval.cxx | 4 ++-- direct/src/interval/waitInterval.cxx | 4 +++- 9 files changed, 39 insertions(+), 31 deletions(-) diff --git a/direct/src/interval/cInterval.I b/direct/src/interval/cInterval.I index 381f963c87..94624d5636 100644 --- a/direct/src/interval/cInterval.I +++ b/direct/src/interval/cInterval.I @@ -233,11 +233,11 @@ recompute() const { // one of the stopped states. //////////////////////////////////////////////////////////////////// INLINE void CInterval:: -check_stopped(const char *method_name) const { +check_stopped(TypeHandle type, const char *method_name) const { if (_state == S_started) { interval_cat.warning() - << get_name() << "." << method_name << "() called in state " - << _state << ".\n"; + << type.get_name() << "::" << method_name << "() called for " + << get_name() << " in state " << _state << ".\n"; nassertv(!verify_intervals); } } @@ -249,11 +249,11 @@ check_stopped(const char *method_name) const { // one of the started states. //////////////////////////////////////////////////////////////////// INLINE void CInterval:: -check_started(const char *method_name) const { +check_started(TypeHandle type, const char *method_name) const { if (_state != S_started && _state != S_paused) { interval_cat.warning() - << get_name() << "." << method_name << "() called in state " - << _state << ".\n"; + << type.get_name() << "::" << method_name << "() called for " + << get_name() << " in state " << _state << ".\n"; nassertv(!verify_intervals); } } diff --git a/direct/src/interval/cInterval.cxx b/direct/src/interval/cInterval.cxx index 602808401e..d477f3d00f 100644 --- a/direct/src/interval/cInterval.cxx +++ b/direct/src/interval/cInterval.cxx @@ -51,6 +51,7 @@ CInterval(const string &name, double duration, bool open_ended) : _play_rate = 1.0; _do_loop = false; _loop_count = 0; + nassertv(_duration >= 0.0); } //////////////////////////////////////////////////////////////////// @@ -250,7 +251,7 @@ priv_do_event(double t, EventType event) { //////////////////////////////////////////////////////////////////// void CInterval:: priv_initialize(double t) { - check_stopped("priv_initialize"); + check_stopped(get_class_type(), "priv_initialize"); recompute(); _state = S_started; priv_step(t); @@ -266,7 +267,7 @@ priv_initialize(double t) { //////////////////////////////////////////////////////////////////// void CInterval:: priv_instant() { - check_stopped("priv_instant"); + check_stopped(get_class_type(), "priv_instant"); recompute(); _state = S_started; priv_step(get_duration()); @@ -283,7 +284,7 @@ priv_instant() { //////////////////////////////////////////////////////////////////// void CInterval:: priv_step(double t) { - check_started("priv_step"); + check_started(get_class_type(), "priv_step"); _state = S_started; _curr_t = t; } @@ -298,7 +299,7 @@ priv_step(double t) { //////////////////////////////////////////////////////////////////// void CInterval:: priv_finalize() { - check_started("priv_step"); + check_started(get_class_type(), "priv_finalize"); double duration = get_duration(); priv_step(duration); _state = S_final; @@ -315,7 +316,7 @@ priv_finalize() { //////////////////////////////////////////////////////////////////// void CInterval:: priv_reverse_initialize(double t) { - check_stopped("priv_reverse_initialize"); + check_stopped(get_class_type(), "priv_reverse_initialize"); recompute(); _state = S_started; priv_step(t); @@ -332,7 +333,7 @@ priv_reverse_initialize(double t) { //////////////////////////////////////////////////////////////////// void CInterval:: priv_reverse_instant() { - check_stopped("priv_reverse_instant"); + check_stopped(get_class_type(), "priv_reverse_instant"); recompute(); _state = S_started; priv_step(0.0); @@ -348,7 +349,7 @@ priv_reverse_instant() { //////////////////////////////////////////////////////////////////// void CInterval:: priv_reverse_finalize() { - check_started("priv_reverse_finalize"); + check_started(get_class_type(), "priv_reverse_finalize"); priv_step(0.0); _state = S_initial; } @@ -369,7 +370,7 @@ priv_reverse_finalize() { //////////////////////////////////////////////////////////////////// void CInterval:: priv_interrupt() { - check_started("priv_interrupt"); + check_started(get_class_type(), "priv_interrupt"); _state = S_paused; } diff --git a/direct/src/interval/cInterval.h b/direct/src/interval/cInterval.h index eb0fd15db5..4599aa75ac 100644 --- a/direct/src/interval/cInterval.h +++ b/direct/src/interval/cInterval.h @@ -127,8 +127,8 @@ protected: INLINE void recompute() const; virtual void do_recompute(); - INLINE void check_stopped(const char *method_name) const; - INLINE void check_started(const char *method_name) const; + INLINE void check_stopped(TypeHandle type, const char *method_name) const; + INLINE void check_started(TypeHandle type, const char *method_name) const; State _state; double _curr_t; diff --git a/direct/src/interval/cLerpAnimEffectInterval.cxx b/direct/src/interval/cLerpAnimEffectInterval.cxx index 4fbabe9a40..0b6f75a2cb 100644 --- a/direct/src/interval/cLerpAnimEffectInterval.cxx +++ b/direct/src/interval/cLerpAnimEffectInterval.cxx @@ -31,7 +31,7 @@ TypeHandle CLerpAnimEffectInterval::_type_handle; //////////////////////////////////////////////////////////////////// void CLerpAnimEffectInterval:: priv_step(double t) { - check_started("step"); + check_started(get_class_type(), "priv_step"); _state = S_started; double d = compute_delta(t); diff --git a/direct/src/interval/cLerpNodePathInterval.cxx b/direct/src/interval/cLerpNodePathInterval.cxx index 66d224bf88..b57d43606b 100644 --- a/direct/src/interval/cLerpNodePathInterval.cxx +++ b/direct/src/interval/cLerpNodePathInterval.cxx @@ -81,7 +81,7 @@ CLerpNodePathInterval(const string &name, double duration, //////////////////////////////////////////////////////////////////// void CLerpNodePathInterval:: priv_initialize(double t) { - check_stopped("initialize"); + check_stopped(get_class_type(), "priv_initialize"); recompute(); _prev_d = 0.0; _state = S_started; @@ -98,7 +98,7 @@ priv_initialize(double t) { //////////////////////////////////////////////////////////////////// void CLerpNodePathInterval:: priv_instant() { - check_stopped("instant"); + check_stopped(get_class_type(), "priv_instant"); recompute(); _prev_d = 0.0; _state = S_started; @@ -115,7 +115,7 @@ priv_instant() { //////////////////////////////////////////////////////////////////// void CLerpNodePathInterval:: priv_step(double t) { - check_started("step"); + check_started(get_class_type(), "priv_step"); _state = S_started; double d = compute_delta(t); @@ -316,7 +316,7 @@ priv_step(double t) { //////////////////////////////////////////////////////////////////// void CLerpNodePathInterval:: priv_reverse_initialize(double t) { - check_stopped("reverse_initialize"); + check_stopped(get_class_type(), "priv_reverse_initialize"); recompute(); _state = S_started; _prev_d = 1.0; @@ -334,7 +334,7 @@ priv_reverse_initialize(double t) { //////////////////////////////////////////////////////////////////// void CLerpNodePathInterval:: priv_reverse_instant() { - check_stopped("reverse_initialize"); + check_stopped(get_class_type(), "priv_reverse_initialize"); recompute(); _state = S_started; _prev_d = 1.0; diff --git a/direct/src/interval/cMetaInterval.cxx b/direct/src/interval/cMetaInterval.cxx index 37521bcaa0..2ed980fb03 100644 --- a/direct/src/interval/cMetaInterval.cxx +++ b/direct/src/interval/cMetaInterval.cxx @@ -364,7 +364,7 @@ priv_initialize(double t) { return; } - check_stopped("priv_initialize"); + check_stopped(get_class_type(), "priv_initialize"); // It may be tempting to flush the event_queue here, but don't do // it. Those are events that must still be serviced from some // previous interval operation. Throwing them away would be a @@ -419,7 +419,7 @@ priv_instant() { return; } - check_stopped("priv_instant"); + check_stopped(get_class_type(), "priv_instant"); recompute(); _active.clear(); @@ -460,7 +460,7 @@ priv_step(double t) { return; } - check_started("priv_step"); + check_started(get_class_type(), "priv_step"); int now = double_to_int_time(t); /* @@ -568,7 +568,7 @@ priv_reverse_initialize(double t) { return; } - check_stopped("priv_reverse_initialize"); + check_stopped(get_class_type(), "priv_reverse_initialize"); // It may be tempting to flush the event_queue here, but don't do // it. Those are events that must still be serviced from some // previous interval operation. Throwing them away would be a @@ -624,7 +624,7 @@ priv_reverse_instant() { return; } - check_stopped("priv_reverse_instant"); + check_stopped(get_class_type(), "priv_reverse_instant"); recompute(); _active.clear(); @@ -1176,7 +1176,8 @@ recompute_level(int n, int level_begin, int &level_end) { while (n < (int)_defs.size() && _defs[n]._type != DT_pop_level) { IntervalDef &def = _defs[n]; - int begin_time, end_time; + int begin_time = previous_begin; + int end_time = previous_end; switch (def._type) { case DT_c_interval: begin_time = get_begin_time(def, level_begin, previous_begin, previous_end); diff --git a/direct/src/interval/hideInterval.cxx b/direct/src/interval/hideInterval.cxx index b4955b18f4..057482d389 100644 --- a/direct/src/interval/hideInterval.cxx +++ b/direct/src/interval/hideInterval.cxx @@ -50,7 +50,9 @@ HideInterval(const NodePath &node, const string &name) : //////////////////////////////////////////////////////////////////// void HideInterval:: priv_instant() { + check_stopped(get_class_type(), "priv_instant"); _node.hide(); + _state = S_final; } //////////////////////////////////////////////////////////////////// @@ -64,5 +66,7 @@ priv_instant() { //////////////////////////////////////////////////////////////////// void HideInterval:: priv_reverse_instant() { + check_stopped(get_class_type(), "priv_reverse_instant"); _node.show(); + _state = S_initial; } diff --git a/direct/src/interval/showInterval.cxx b/direct/src/interval/showInterval.cxx index 2d0fecb996..d0019e286c 100644 --- a/direct/src/interval/showInterval.cxx +++ b/direct/src/interval/showInterval.cxx @@ -50,7 +50,7 @@ ShowInterval(const NodePath &node, const string &name) : //////////////////////////////////////////////////////////////////// void ShowInterval:: priv_instant() { - check_stopped("instant"); + check_stopped(get_class_type(), "priv_instant"); _node.show(); _state = S_final; } @@ -66,7 +66,7 @@ priv_instant() { //////////////////////////////////////////////////////////////////// void ShowInterval:: priv_reverse_instant() { - check_stopped("instant"); + check_stopped(get_class_type(), "priv_reverse_instant"); _node.hide(); _state = S_initial; } diff --git a/direct/src/interval/waitInterval.cxx b/direct/src/interval/waitInterval.cxx index c841150491..2cf945e249 100644 --- a/direct/src/interval/waitInterval.cxx +++ b/direct/src/interval/waitInterval.cxx @@ -30,13 +30,15 @@ TypeHandle WaitInterval::_type_handle; //////////////////////////////////////////////////////////////////// void WaitInterval:: priv_step(double t) { + // The WaitInterval is normally not run directly; it just fills up + // time when constructing a MetaInterval (specifically, a Sequence). #ifndef NDEBUG if (verify_intervals) { interval_cat.info() << "running WaitInterval. Intentional?\n"; } #endif - check_started("priv_step"); + check_started(get_class_type(), "priv_step"); _state = S_started; _curr_t = t; }