Browse Source

add null check for set Zoom, add type check also for resize (#724)

cleaner code, addition to #655 and #724
sschmid 5 years ago
parent
commit
f0201b4c4f
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

+ 4 - 2
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -614,7 +614,7 @@ export class OpenSheetMusicDisplay {
                 //self.container.style.width = width + "px";
 
                 // recalculate beems, are otherwise not updated and can detach from beams, see #724
-                if (this.graphic?.GetCalculator) {
+                if (this.graphic?.GetCalculator instanceof VexFlowMusicSheetCalculator) { // null and type check
                     (this.graphic.GetCalculator as VexFlowMusicSheetCalculator).beamsNeedUpdate = true;
                 }
                 if (self.IsReadyToRender()) {
@@ -848,7 +848,9 @@ export class OpenSheetMusicDisplay {
     public set Zoom(value: number) {
         this.zoom = value;
         this.zoomUpdated = true;
-        (this.graphic.GetCalculator as VexFlowMusicSheetCalculator).beamsNeedUpdate = this.zoomUpdated;
+        if (this.graphic?.GetCalculator instanceof VexFlowMusicSheetCalculator) { // null and type check
+            (this.graphic.GetCalculator as VexFlowMusicSheetCalculator).beamsNeedUpdate = this.zoomUpdated;
+        }
     }
 
     public set FollowCursor(value: boolean) {