Quellcode durchsuchen

fix(Slurs): fix undefined slur error in beethoven moonlight sonata (#679)

fix #679
sschmid vor 5 Jahren
Ursprung
Commit
d23581fa6f
1 geänderte Dateien mit 5 neuen und 0 gelöschten Zeilen
  1. 5 0
      src/MusicalScore/Graphical/GraphicalSlur.ts

+ 5 - 0
src/MusicalScore/Graphical/GraphicalSlur.ts

@@ -34,6 +34,11 @@ export class GraphicalSlur extends GraphicalCurve {
      * @param y
      */
     public static Compare (x: GraphicalSlur, y: GraphicalSlur ): number {
+        if (x.staffEntries.length < 1) { // x.staffEntries[i] can return undefined in Beethoven Moonlight Sonata sample
+            return -1;
+        } else if (y.staffEntries.length < 1) {
+            return 1;
+        }
         const xTimestampSpan: Fraction = Fraction.minus(x.staffEntries[x.staffEntries.length - 1].getAbsoluteTimestamp(),
                                                         x.staffEntries[0].getAbsoluteTimestamp());
         const yTimestampSpan: Fraction = Fraction.minus(y.staffEntries[y.staffEntries.length - 1].getAbsoluteTimestamp(),