swift- get exc_bad_instruction (code=exc_i386_invop, subcode=0x0) 在 while 循环中替换数组值
swift- get exc_bad_instruction (code=exc_i386_invop, subcode=0x0) with array value replacement in while loop
我正在做一个笔记应用程序。在这个应用程序中,我将线条变成贝塞尔曲线。目前,当我尝试将新值放入在 while 循环之外定义的矩阵时出现错误。当放入一个虚拟变量时,我已经单独尝试了表达式并且它在循环中工作。当我使用格式替换二维变量的值时,它在循环外工作,但是,当我在循环中同时执行这两个操作时,它不起作用。
//: Playground - noun: a place where people can play
import UIKit
var x2 = 6.0
var y2 = 5.0
var x1 = 1.0
var y1 = 1.0
var p1x = 2.0
var p1y = 3.0
var B = 6.5
var Ba = 2.2
var percentall = Ba/B
var yall = 5.0
var xall = 1.0
var A = 4.0
var C = 5.0
var Ct = 0.0
var At = 0.0
var Aall = Int(A) * 10
var Call = Int(C) * 10
var thelistx = [[Double]](count: Call, repeatedValue: [Double](count: Call, repeatedValue: 0.0 ))
var thelisty = Array(count: Aall, repeatedValue: Array(count: Call, repeatedValue: 0.0 ))
var theAt = 0
var theCt = 0
while At <= A {
var Apercent = percentall * At
var Aend = y1 + At
var yslope = (A - At) * percentall + Aend
var lefty = (yslope - Apercent) * percentall + Apercent
var righty = ( y2 - yslope) * percentall + yslope
while Ct <= C {
var Cpercent = percentall * Ct
var Cend = x2 - Ct
var xslope = (C - Ct) * percentall + Cend
var leftx = (xslope - x1) * percentall + x1
var rightx = (x2 - xslope) * percentall + xslope
thelistx [theAt] [theCt] = (rightx - leftx) * percentall + left
*********************Execution was interrupted, reason exc_bad_instruction (code=exc_i386_invop, subcode=0x0) ***************
thelisty [theAt] [theCt] = (righty - lefty) * percentall + lefty
Ct += 0.1
theCt += 1
}
At = At + 0.1
theAt += 1
}
控制台显示您的错误是什么:
fatal error: Index out of range
您将越界 thelistx [theAt] [theCt]
将 while Ct < C
更改为 Ct < C - 1
让您的调用保持在数组的范围内。
我正在做一个笔记应用程序。在这个应用程序中,我将线条变成贝塞尔曲线。目前,当我尝试将新值放入在 while 循环之外定义的矩阵时出现错误。当放入一个虚拟变量时,我已经单独尝试了表达式并且它在循环中工作。当我使用格式替换二维变量的值时,它在循环外工作,但是,当我在循环中同时执行这两个操作时,它不起作用。
//: Playground - noun: a place where people can play
import UIKit
var x2 = 6.0
var y2 = 5.0
var x1 = 1.0
var y1 = 1.0
var p1x = 2.0
var p1y = 3.0
var B = 6.5
var Ba = 2.2
var percentall = Ba/B
var yall = 5.0
var xall = 1.0
var A = 4.0
var C = 5.0
var Ct = 0.0
var At = 0.0
var Aall = Int(A) * 10
var Call = Int(C) * 10
var thelistx = [[Double]](count: Call, repeatedValue: [Double](count: Call, repeatedValue: 0.0 ))
var thelisty = Array(count: Aall, repeatedValue: Array(count: Call, repeatedValue: 0.0 ))
var theAt = 0
var theCt = 0
while At <= A {
var Apercent = percentall * At
var Aend = y1 + At
var yslope = (A - At) * percentall + Aend
var lefty = (yslope - Apercent) * percentall + Apercent
var righty = ( y2 - yslope) * percentall + yslope
while Ct <= C {
var Cpercent = percentall * Ct
var Cend = x2 - Ct
var xslope = (C - Ct) * percentall + Cend
var leftx = (xslope - x1) * percentall + x1
var rightx = (x2 - xslope) * percentall + xslope
thelistx [theAt] [theCt] = (rightx - leftx) * percentall + left
*********************Execution was interrupted, reason exc_bad_instruction (code=exc_i386_invop, subcode=0x0) ***************
thelisty [theAt] [theCt] = (righty - lefty) * percentall + lefty
Ct += 0.1
theCt += 1
}
At = At + 0.1
theAt += 1
}
控制台显示您的错误是什么:
fatal error: Index out of range
您将越界 thelistx [theAt] [theCt]
将 while Ct < C
更改为 Ct < C - 1
让您的调用保持在数组的范围内。