瀏覽代碼

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

cleaner code, addition to #655 and #724
sschmid 5 年之前
父節點
當前提交
f0201b4c4f
共有 1 個文件被更改,包括 4 次插入2 次删除
  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";
                 //self.container.style.width = width + "px";
 
 
                 // recalculate beems, are otherwise not updated and can detach from beams, see #724
                 // 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;
                     (this.graphic.GetCalculator as VexFlowMusicSheetCalculator).beamsNeedUpdate = true;
                 }
                 }
                 if (self.IsReadyToRender()) {
                 if (self.IsReadyToRender()) {
@@ -848,7 +848,9 @@ export class OpenSheetMusicDisplay {
     public set Zoom(value: number) {
     public set Zoom(value: number) {
         this.zoom = value;
         this.zoom = value;
         this.zoomUpdated = true;
         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) {
     public set FollowCursor(value: boolean) {