Permalink
Browse files

fix #14764

convert qDebug();abort() to qFatal() and if(cond) abort() to
Q_ASSERT(!cond), esp. for the benefit of Windows, where it is impossible
to set a breakpoint on the abort()
Also modernizing mscoreMessageHandler() and making it more informative
by adding file, line and function to the output.
  • Loading branch information...
1 parent e013855 commit 3adc1ea6ed16def8cd944768c79a2c98d31c1a87 @Jojo-Schmitz Jojo-Schmitz committed Mar 4, 2014
View
@@ -353,8 +353,7 @@ Accidental::AccidentalType Accidental::value2subtype(AccidentalVal v)
case FLAT: return ACC_FLAT;
case FLAT2: return ACC_FLAT2;
default:
- qDebug("value2subtype: illegal accidental val %d\n", v);
- abort();
+ qFatal("value2subtype: illegal accidental val %d\n", v);
}
return ACC_NONE;
}
View
@@ -922,8 +922,7 @@ void ChordRest::add(Element* e)
}
break;
default:
- qDebug("ChordRest::add: unknown element %s", e->name());
- abort();
+ qFatal("ChordRest::add: unknown element %s", e->name());
break;
}
}
@@ -958,8 +957,7 @@ void ChordRest::remove(Element* e)
qDebug("ChordRest::remove: %s %p not found", e->name(), e);
break;
default:
- qDebug("ChordRest::remove: unknown element <%s>", e->name());
- abort();
+ qFatal("ChordRest::remove: unknown element <%s>", e->name());
}
}
View
@@ -417,8 +417,7 @@ bool Score::rewriteMeasures(Measure* fm, Measure* lm, const Fraction& ns)
nfm = m;
}
if (!range.write(0, nfm)) {
- qDebug("cannot write measures\n");
- abort();
+ qFatal("Cannot write measures\n");
}
nlm->setEndBarLineType(lm->endBarLineType(), lm->endBarLineGenerated(),
lm->endBarLineVisible(), lm->endBarLineColor());
View
@@ -531,7 +531,7 @@ QPointF Element::pagePos() const
else if (parent()->type() == SYSTEM)
system = static_cast<System*>(parent());
else
- abort();
+ Q_ASSERT(false);
if (system) {
int si = staffIdx();
if (type() == CHORD || type() == REST)
@@ -556,6 +556,7 @@ QPointF Element::canvasPos() const
QPointF p(pos());
if (parent() == 0)
return p;
+
if (_flags & ELEMENT_ON_STAFF) {
System* system;
if (parent()->type() == SEGMENT)
@@ -565,7 +566,7 @@ QPointF Element::canvasPos() const
else if (parent()->type() == SYSTEM)
system = static_cast<System*>(parent());
else
- abort();
+ Q_ASSERT(false);
if (system) {
int si = staffIdx();
if (type() == CHORD || type() == REST)
@@ -1277,8 +1278,7 @@ void Element::add(Element* e)
void Element::remove(Element* e)
{
- qDebug("Element: cannot remove %s from %s\n", e->name(), name());
- abort();
+ qFatal("Element: cannot remove %s from %s\n", e->name(), name());
}
//---------------------------------------------------------
@@ -1520,9 +1520,8 @@ bool Element::setProperty(P_ID propertyId, const QVariant& v)
_placement = Placement(v.toInt());
break;
default:
- qDebug("Element::setProperty: unknown <%s>(%d), data <%s>",
+ qFatal("Element::setProperty: unknown <%s>(%d), data <%s>",
propertyName(propertyId), propertyId, qPrintable(v.toString()));
- abort();
return false;
}
setGenerated(false);
View
@@ -1875,8 +1875,7 @@ QList<System*> Score::layoutSystemRow(qreal rowWidth, bool isFirstSystem, bool u
//
if (system->measures().isEmpty()) {
- qDebug("system %p is empty\n", system);
- abort();
+ qFatal("System %p is empty\n", system);
}
Measure* m = system->lastMeasure();
bool hasCourtesyKeysig = false;
View
@@ -157,8 +157,7 @@ void MCursor::addPart(const QString& instrument)
Staff* staff = new Staff(_score, part, 0);
InstrumentTemplate* it = searchTemplate(instrument);
if (it == 0) {
- printf("did not found instrument <%s>\n", qPrintable(instrument));
- abort();
+ qFatal("Did not find instrument <%s>\n", qPrintable(instrument));
}
part->initFromInstrTemplate(it);
_score->appendPart(part);
@@ -173,8 +172,7 @@ void MCursor::saveScore()
{
QFile fp(_score->name() + ".mscx");
if (!fp.open(QIODevice::WriteOnly)) {
- fprintf(stderr, "open <%s> failed\n", qPrintable(fp.fileName()));
- abort();
+ qFatal("Open <%s> failed\n", qPrintable(fp.fileName()));
}
_score->saveFile(&fp, false);
fp.close();
View
@@ -310,8 +310,7 @@ void Note::setTpcFromPitch()
void Note::setTpc(int v)
{
if (!tpcIsValid(v)) {
- qDebug("Note::setTpc: bad tpc %d\n", v);
- abort();
+ qFatal("Note::setTpc: bad tpc %d\n", v);
}
_tpc = v;
}
@@ -187,8 +187,7 @@ int tpc2pitch(int tpc)
7, 2, 9, 4, 11, 6, 13 // ##
};
if (tpc < 0 || tpc >= int(sizeof(pitches)/sizeof(*pitches))) {
- qDebug("tpc %d >= %d\n", tpc, int(sizeof(pitches)/sizeof(*pitches)));
- abort();
+ qFatal("tpc %d >= %d\n", tpc, int(sizeof(pitches)/sizeof(*pitches)));
}
return pitches[tpc];
}
@@ -467,14 +466,10 @@ static const int enharmonicSpelling[15][34] = {
static int penalty(int lof1, int lof2, int k)
{
- if (k < 0 || k >= 15) {
- qDebug("illegal key %d >= 15\n", k);
- abort();
- }
- if (lof1 < 0 || lof1 >= 34)
- abort();
- if (lof2 < 0 || lof2 >= 34)
- abort();
+ if (k < 0 || k >= 15)
+ qFatal("Illegal key %d >= 15\n", k);
+ Q_ASSERT(lof1 >= 0 && lof1 < 34);
+ Q_ASSERT(lof2 >= 0 && lof2 < 34);
int penalty = enharmonicSpelling[k][lof1] * 4 + enharmonicSpelling[k][lof2] * 4;
int distance = lof2 > lof1 ? lof2 - lof1 : lof1 - lof2;
if (distance > 12)
@@ -498,8 +493,7 @@ static int computeWindow(const QList<Event>& notes, int start, int end, int keyI
int idx = -1;
int pitch[10];
- if ((end-start) >= 10 || start == end)
- abort();
+ Q_ASSERT((end-start) < 10 && start != end);
int i = start;
int k = 0;
@@ -513,15 +507,13 @@ static int computeWindow(const QList<Event>& notes, int start, int end, int keyI
int pa = 0;
int pb = 0;
int l = pitch[0] * 2 + (i & 1);
- if ((l < 0) || (l >= int(sizeof(tab1)/sizeof(*tab1))))
- abort();
+ Q_ASSERT((l >= 0) && (l < int(sizeof(tab1)/sizeof(*tab1))));
int lof1a = tab1[l];
int lof1b = tab2[l];
for (int k = 1; k < 10; ++k) {
int l = pitch[k] * 2 + ((i & (1 << k)) >> k);
- if ((l < 0) || (l >= int(sizeof(tab1)/sizeof(*tab1))))
- abort();
+ Q_ASSERT((l >= 0) && (l < int(sizeof(tab1)/sizeof(*tab1))));
int lof2a = tab1[l];
int lof2b = tab2[l];
pa += penalty(lof1a, lof2a, keyIdx);
@@ -559,8 +551,7 @@ int tpc(int idx, int pitch, int opt)
else
tab = tab1;
int i = (pitch % 12) * 2 + ((opt & (1 << idx)) >> idx);
- if (i < 0 || i >= 24)
- abort();
+ Q_ASSERT(i >= 0 && i < 24);
return tab[i];
}
@@ -600,15 +591,13 @@ int computeWindow(const QList<Note*>& notes, int start, int end)
int pa = 0;
int pb = 0;
int l = pitch[0] * 2 + (i & 1);
- if (l < 0 || l > (int)(sizeof(tab1)/sizeof(*tab1)))
- abort();
+ Q_ASSERT(l >= 0 && l <= (int)(sizeof(tab1)/sizeof(*tab1)));
int lof1a = tab1[l];
int lof1b = tab2[l];
for (int k = 1; k < 10; ++k) {
int l = pitch[k] * 2 + ((i & (1 << k)) >> k);
- if (l < 0 || l > (int)(sizeof(tab1)/sizeof(*tab1)))
- abort();
+ Q_ASSERT(l >= 0 && l <= (int)(sizeof(tab1)/sizeof(*tab1)));
int lof2a = tab1[l];
int lof2b = tab2[l];
pa += penalty(lof1a, lof2a, key[k]);
View
@@ -148,8 +148,7 @@ void TrackList::read(int track, const Segment* fs, const Segment* es)
if (de->tuplet()) {
Tuplet* tuplet = de->tuplet();
if (tuplet->elements().front() != de) {
- qDebug("TrackList::read: cannot start in middle of tuplet");
- abort();
+ qFatal("TrackList::read: cannot start in middle of tuplet");
}
de = tuplet;
@@ -412,7 +411,7 @@ bool TrackList::write(int track, Measure* measure) const
}
rest = Fraction();
duration = Fraction();
- abort();
+ Q_ASSERT(false);
}
}
}
View
@@ -176,8 +176,7 @@ int RepeatList::utick2tick(int tick) const
}
}
if (MScore::debugMode) {
- qDebug("utick %d not found in RepeatList\n", tick);
- abort();
+ qFatal("utick %d not found in RepeatList\n", tick);
}
return 0;
}
@@ -228,8 +227,7 @@ int RepeatList::utime2utick(qreal t) const
}
}
if (MScore::debugMode) {
- qDebug("time %f not found in RepeatList\n", t);
- abort();
+ qFatal("time %f not found in RepeatList\n", t);
}
return 0;
}
View
@@ -2335,8 +2335,7 @@ void Score::splitStaff(int staffIdx, int splitPoint)
if (note->pitch() >= splitPoint)
continue;
Chord* chord = static_cast<Chord*>(s->element(dtrack + voice));
- if (chord && (chord->type() != Element::CHORD))
- abort();
+ Q_ASSERT(!chord || (chord->type() == Element::CHORD));
if (chord == 0) {
chord = new Chord(*c);
foreach(Note* note, chord->notes())
View
@@ -156,8 +156,7 @@ Segment::Segment(const Segment& s)
void Segment::setSegmentType(SegmentType t)
{
- if (_segmentType == SegClef && t == SegChordRest)
- abort();
+ Q_ASSERT(_segmentType != SegClef || t != SegChordRest);
_segmentType = t;
}
@@ -517,8 +516,7 @@ void Segment::add(Element* el)
break;
default:
- qDebug("Segment::add() unknown %s", el->name());
- abort();
+ qFatal("Segment::add() unknown %s", el->name());
}
}
@@ -602,8 +600,7 @@ void Segment::remove(Element* el)
break;
default:
- qDebug("Segment::remove() unknown %s", el->name());
- abort();
+ qFatal("Segment::remove() unknown %s", el->name());
}
checkEmpty();
@@ -65,9 +65,8 @@ void SegmentList::check()
qFatal("SegmentList::check: bad last");
}
if (n != _size) {
- qDebug("SegmentList::check: counted %d but _size is %d", n, _size);
+ qFatal("SegmentList::check: counted %d but _size is %d", n, _size);
_size = n;
- abort();
}
}
#endif
View
@@ -23,8 +23,7 @@ static int ticks_beat(int n)
{
int m = (MScore::division * 4) / n;
if ((MScore::division * 4) % n) {
- qDebug("Mscore: ticks_beat(): bad divisor %d", n);
- abort();
+ qFatal("Mscore: ticks_beat(): bad divisor %d", n);
}
return m;
}
@@ -140,8 +139,7 @@ void TimeSigMap::tickValues(int t, int* bar, int* beat, int* tick) const
}
auto e = upper_bound(t);
if (empty() || e == begin()) {
- qDebug("tickValue(0x%x) not found", t);
- abort();
+ qFatal("tickValue(0x%x) not found", t);
}
--e;
int delta = t - e->first;
View
@@ -1134,8 +1134,7 @@ const TextStyle& StyleData::textStyle(const QString& name) const
if (s.name() == name)
return s;
}
- qDebug("TextStyle <%s> not found", qPrintable(name));
- abort();
+ qFatal("TextStyle <%s> not found", qPrintable(name));
return _textStyles[0];
}
View
@@ -678,8 +678,7 @@ void Tuplet::add(Element* e)
#ifndef NDEBUG
foreach(DurationElement* el, _elements) {
if (el == e) {
- qDebug("Tuplet::add: %p %s already there", e, e->name());
- abort();
+ qFatal("Tuplet::add: %p %s already there", e, e->name());
}
}
#endif
View
@@ -1674,8 +1674,7 @@ void SortStaves::undo()
ChangePitch::ChangePitch(Note* _note, int _pitch, int _tpc, int l/*, int f, int s*/)
{
note = _note;
- if (_note == 0)
- abort();
+ Q_ASSERT(_note != 0);
pitch = _pitch;
tpc = _tpc;
line = l;
View
@@ -174,10 +174,9 @@ void XmlReader::unknown() const
{
if (QXmlStreamReader::error())
qDebug("StreamReaderError: %s", qPrintable(errorString()));
- qDebug("%s: xml read error at line %lld col %lld: %s",
+ qFatal("%s: xml read error at line %lld col %lld: %s",
qPrintable(docName), lineNumber(), columnNumber(),
name().toUtf8().data());
- abort();
// skipCurrentElement();
}
@@ -492,7 +491,7 @@ void Xml::tag(P_ID id, QVariant data, QVariant defaultData)
tag(name, Sym::id2name(SymId(data.toInt())));
break;
default:
- abort();
+ Q_ASSERT(false);
}
}
View
@@ -106,8 +106,7 @@ static void parseClass(const QString& name, const QString& in)
QRegExp re4 ("class +(\\w+) *: *public +(\\w+) *\\{");
QRegExp re4b("class +(\\w+) *: *public +(\\w+), *public");
- if (!re1.isValid() || !re2.isValid() || !re3.isValid())
- abort();
+ Q_ASSERT(re1.isValid() && re2.isValid() && re3.isValid());
bool parseClassDescription = true;
View
@@ -674,10 +674,8 @@ void BBFile::convertTrack(Score* score, BBTrack* track, int staffIdx)
int restLen = e.ontime() - ctick;
// qDebug("ctick %d rest %d ontick %d size %d", ctick, restLen, e.ontime(), notes.size());
- if (restLen <= 0) {
- qDebug("bad restlen ontime %d - ctick %d", e.ontime(), ctick);
- abort();
- }
+ if (restLen <= 0)
+ qFatal("bad restlen ontime %d - ctick %d", e.ontime(), ctick);
while (!notes.isEmpty()) {
int len = processPendingNotes(score, &notes, restLen, track);
Oops, something went wrong.

0 comments on commit 3adc1ea

Please sign in to comment.