AwesomeMenu icon indicating copy to clipboard operation
AwesomeMenu copied to clipboard

Crash Issue in _expand function for using only one AwsomeMenu item

Open vksmaini opened this issue 11 years ago • 5 comments

Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y)), function void CGPathAddLineToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat), file Paths/CGPath.cc

vksmaini avatar Dec 05 '13 08:12 vksmaini

Is anybody there who can explain this to me?

vksmaini avatar Dec 10 '13 12:12 vksmaini

It happens to me too. I realized that happens when I´ve got only one menuitem. I quick solve this with:

    CGPoint endPoint = CGPointMake(startPoint.x + endRadius * sinf(i * menuWholeAngle / (count - 1)), startPoint.y - endRadius * cosf(i * menuWholeAngle / (count - 1)));
    if(isnan(endPoint.x)) endPoint = CGPointZero;
    item.endPoint = RotateCGPointAroundCenter(endPoint, startPoint, rotateAngle);

    CGPoint nearPoint = CGPointMake(startPoint.x + nearRadius * sinf(i * menuWholeAngle / (count - 1)), startPoint.y - nearRadius * cosf(i * menuWholeAngle / (count - 1)));
    if(isnan(nearPoint.x)) nearPoint = CGPointZero;
    item.nearPoint = RotateCGPointAroundCenter(nearPoint, startPoint, rotateAngle);

    CGPoint farPoint = CGPointMake(startPoint.x + farRadius * sinf(i * menuWholeAngle / (count - 1)), startPoint.y - farRadius * cosf(i * menuWholeAngle / (count - 1)));
    if(isnan(farPoint.x)) farPoint = CGPointZero;
    item.farPoint = RotateCGPointAroundCenter(farPoint, startPoint, rotateAngle);

In method _setMenu in AwesomeMenu.m

It´s not a valid solution, you must hardcode a good values for your porpouses, or even better, a generalistic solution.

dbayon avatar Jan 22 '14 09:01 dbayon

Well yes I hardcoded the values for a single menu item in the end. Anyway thanks for responding.

On Wed, Jan 22, 2014 at 3:25 PM, dbayon [email protected] wrote:

It happens to me too. I realized that happens when I´ve got only one menuitem. I quick solve this with:

CGPoint endPoint = CGPointMake(startPoint.x + endRadius * sinf(i * menuWholeAngle / (count - 1)), startPoint.y - endRadius * cosf(i * menuWholeAngle / (count - 1)));
if(isnan(endPoint.x)) endPoint = CGPointZero;
item.endPoint = RotateCGPointAroundCenter(endPoint, startPoint, rotateAngle);

CGPoint nearPoint = CGPointMake(startPoint.x + nearRadius * sinf(i * menuWholeAngle / (count - 1)), startPoint.y - nearRadius * cosf(i * menuWholeAngle / (count - 1)));
if(isnan(nearPoint.x)) nearPoint = CGPointZero;
item.nearPoint = RotateCGPointAroundCenter(nearPoint, startPoint, rotateAngle);

CGPoint farPoint = CGPointMake(startPoint.x + farRadius * sinf(i * menuWholeAngle / (count - 1)), startPoint.y - farRadius * cosf(i * menuWholeAngle / (count - 1)));
if(isnan(farPoint.x)) farPoint = CGPointZero;
item.farPoint = RotateCGPointAroundCenter(farPoint, startPoint, rotateAngle);

In method _setMenu in AwesomeMenu.m

It´s not a valid solution, you must hardcode a good values for your porpouses, or even better, a generalistic solution.

— Reply to this email directly or view it on GitHubhttps://github.com/levey/AwesomeMenu/issues/48#issuecomment-33007094 .

Regards -- Vikas Maini http://about.me/vikasmaini

vksmaini avatar Jan 22 '14 11:01 vksmaini

Mate, it is still happening. Would you please fix this?

SeanWangDev avatar Mar 06 '15 13:03 SeanWangDev

I debugged, and found that it crashes because the dividend (count-1) is 0. I printed endPoint nearPoint and farPoint are all (x = NaN, y = NaN). When the program uses endPoint.x, It crashes finally. I fix it with:

CGPoint endPoint = CGPointMake(startPoint.x + endRadius * sinf(i * menuWholeAngle / ((count - 1) > 0 ? (count - 1) : 1)), startPoint.y - endRadius * cosf(i * menuWholeAngle / ((count - 1) > 0 ? (count - 1) : 1)) - self.itemDistance * (count - i));
item.endPoint = RotateCGPointAroundCenter(endPoint, startPoint, rotateAngle);
CGPoint nearPoint = CGPointMake(startPoint.x + nearRadius * sinf(i * menuWholeAngle / ((count - 1) > 0 ? (count - 1) : 1)), startPoint.y - nearRadius * cosf(i * menuWholeAngle / ((count - 1) > 0 ? (count - 1) : 1)));
item.nearPoint = RotateCGPointAroundCenter(nearPoint, startPoint, rotateAngle);
CGPoint farPoint = CGPointMake(startPoint.x + farRadius * sinf(i * menuWholeAngle / ((count - 1) > 0 ? (count - 1) : 1)), startPoint.y - farRadius * cosf(i * menuWholeAngle / ((count - 1) > 0 ? (count - 1) : 1)));
item.farPoint = RotateCGPointAroundCenter(farPoint, startPoint, rotateAngle);

I guarantee the dividend is not 0 but 1 if there is only 1 menu item. Sorry for my poor english.

monkiyang avatar Aug 06 '19 07:08 monkiyang