问题
I have a mobile Flex project running on iOS that has been using Degrafa's library in order to use its BezierSpline class. The purpose is to be able to draw directly on the screen, the collection of points given by the user gesture is then converted into a bezier curve using this library.
However, my app has been recently crashing as soon as it was displaying a page containing at least one of these curves. I don't get any error, stacktrace or anything, the app is simply killed and I'm taken back to the iOS desktop. Apparently the error is occurring somewhere inside the .draw() function of the BezierSpline class.
Also, I've noticed that this is only occuring on release versions of the app, either through the AppStore (looks like they didn't notice it) or through a release package deployed on the iPad. Everything is working fine in the emulator or with a debug package directly on the device. Since I haven't made any release packages for some time, I'm not sure which modification may have caused this. The only thing I know is that I've recently updated Flash Builder to 4.7 and AIR to 3.9 (which is required for other features of this project).
So I basically have three questions:
In which case can an app crash only in release mode and not in debug mode? The code remains the same.
Has someone ever encountered that kind of issue using Degrafa and its BezierSpline class?
May this be caused by upgrading AIR to the latest 3.9 version?
EDIT: I've just tested the exact same code under an Android device, the curve is displaying correctly, so this is only occuring when deployed on an iOS device.
回答1:
I ended up implementing this really helpful example written by Lee Burrows here. Here is all I need in a single call:
static public function getPoint(t:Number, points:Array):Point
{
var x:Number = 0;
var y:Number = 0;
var n:uint = points.length-1;
var factn:Number = factoral(n);
for (var i:uint=0;i<=n;i++)
{
//calc binominal coefficent
var b:Number = factn/(factoral(i)*factoral(n-i));
//calc powers
var k:Number = Math.pow(1-t, n-i)*Math.pow(t, i);
//add weighted points to totals
x += b*k*points[i].x;
y += b*k*points[i].y;
}
return new Point(x, y);
}
static private function factoral(value:uint):Number
{
if (value==0) return 1;
var total:Number = value;
while (--value>1)
total *= value;
return total;
}
A sample code using this class is also available at the link above.
The only drawback of this solution is that I have to handle manually the curve smoothness by defining the amount of lines the curve will be made of (by changing "t" incrementation). But I could as well define this incrementation dynamically depending of the amount of control points, or the distance between them.
Anyway this is more than enough for the problem I had, hope this helps someone else.
来源:https://stackoverflow.com/questions/21484326/flex-degrafas-bezier-spline-under-air-3-9