Procházet zdrojové kódy

空卡点数组越界保护

huzhiqiang před 3 roky
rodič
revize
d95f16003b

+ 16 - 5
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -913,6 +913,10 @@ class PQStuckPointEditerController: PQBaseViewController {
         if materialVC != nil, materialVC?.isToPublicHandle != nil {
             materialVC?.isToPublicHandle!(isReCreate, selectedTotalDuration, selectedDataCount, selectedImageDataCount, mStickers, stuckPointMusicData, tempModel)
         } else {
+            if finallyStuckPoints.count == 0 {
+                cShowHUB(superView: nil, msg: "无卡点信息,返回重新选择音乐")
+                return
+            }
             let videoExporter = PQStuckPointPublicController()
             videoExporter.rhythmMode = currentCreateStickersModel
             videoExporter.syncedUpVideoSpeedMin = modelSpeed_maxSpeed
@@ -976,11 +980,14 @@ class PQStuckPointEditerController: PQBaseViewController {
     // 计算拼接音乐的开始和结束点
     func getClipAudioRange() -> CMTimeRange {
         // 设置音乐的拼接范围,开始:推荐的卡点  结束:点到的倒数第二位
-        let lastSecondPoint = Float((stuckPointMusicData!.rhythmSdata[0].pointTimes[stuckPointMusicData!.rhythmSdata[0].pointTimes.count - 2])) / Float(BASE_FILTER_TIMESCALE)
-        let clipAudioRange =
-            CMTimeRange(start: CMTime(value: CMTimeValue(Float(stuckPointMusicData?.startTime ?? 0) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE), end: CMTime(value: CMTimeValue((Float(lastSecondPoint)) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE))
-
-        return clipAudioRange
+        if stuckPointMusicData!.rhythmSdata.count > 0 && stuckPointMusicData?.rhythmSdata[0].pointTimes.count ?? 0 > 2 {
+            let lastSecondPoint = Float((stuckPointMusicData!.rhythmSdata[0].pointTimes[stuckPointMusicData!.rhythmSdata[0].pointTimes.count - 2])) / Float(BASE_FILTER_TIMESCALE)
+            let clipAudioRange =
+                CMTimeRange(start: CMTime(value: CMTimeValue(Float(stuckPointMusicData?.startTime ?? 0) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE), end: CMTime(value: CMTimeValue((Float(lastSecondPoint)) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE))
+            
+            return clipAudioRange
+        }
+        return CMTimeRange(start: CMTime(value: 0, timescale: 1), duration: CMTime(value: 1, timescale: 1))
     }
 
     // 设置播放器
@@ -1456,6 +1463,10 @@ extension PQStuckPointEditerController {
     /// - Parameter seed: 档位速度
     /// - Returns: 最后使用的卡点
     func getUsedStuckPoint(seed: Int) -> Array<Float> {
+        if !(stuckPointMusicData!.rhythmSdata.count > 0 && stuckPointMusicData!.rhythmSdata[0].pointTimes > 1){
+            return []
+        }
+        
         // 推荐卡点数
         var stuckPoints: Array = Array<Float>.init()