jbenet / ios-ntp

SNTP implementation for iOS
http://code.google.com/p/ios-ntp/
MIT License
370 stars 112 forks source link

EXC_BAD_ACCESS #50

Closed NunoMiguelVeloso closed 7 years ago

NunoMiguelVeloso commented 7 years ago

Hi, I'm having issues when I call networkOffset method, I get a bad_access error.

@interface NTPClient:NSObject{
    NetworkClock * nc;
}
- (id)init;
- (bool)isInitialized;
- (Array<int>)now;
@end

@implementation NTPClient

- (id)init {
    self = [super init];
    nc = [NetworkClock sharedNetworkClock];
//    NSDate * nt= nc.networkTime; <-----It's fine if I call it here
    return self;
}

- (bool) isInitialized{
    return true;
}

- (Array<int>) now {
//    nc = [NetworkClock sharedNetworkClock];
    NSDate * nt= nc.networkTime; // <-------------- It breaks here

    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:nt];

    Array<int> a= *new Array<int>;
    a[0] = (int)[components year];
    a[1] = (int)[components month];
    a[2] = (int)[components day];
    a[3] = (int)[components hour];
    a[4] = (int)[components minute];
    a[5] = (int)[components second];
    a[6] = 0;
    return a;
}

@end

Thanks

gavineadie commented 7 years ago

I'm away from home till middle of next week ..

gavineadie commented 7 years ago

.. but just looking at the above code, it doesn't make sense. It doesn't call the "networkOffset" method that you say is failing, and it certainly won't compile as provided.

NunoMiguelVeloso commented 7 years ago

I'm sorry, I meant to say that it's failing when I call "networkTime" and not "networkOffset". Any suggestion? Thanks

gavineadie commented 7 years ago

After turning your example code into actual Objective-C and constructing an application to host it, I can find no problem; NSDate * nt = nc.networkTime provides a date in both places you call it. I did have to remove all the Array<int> uses, of course, because they won't even compile.

This isn't a ios-ntp problem so I'm closing this issue.

NunoMiguelVeloso commented 7 years ago

Hello @gavineadie,

Thanks a lot all your support. I'm building my app with MonkeyX and I can see now that it's a MonkeyX related problem.

Regards, Nuno

gavineadie commented 7 years ago

Interesting .. I didn't know about MonkeyX .. Live and learn !!