I am seeing odd behavior with CGRectIntegral. This is my code:
CGRect rect = CGRectMake(75, 22, 235, 48.000000000000007);
rect = CGRectIntegral(rect);
NSAssert1(rect.size.height == 49, #"I expected 49, but I got: %f!", rect.size.height);
// works on 32 bit iPhone simulator
// throws an exception on iPhone 64 bit simulator & iPhone 5s:
// Terminating app due to uncaught exception 'NSInternalInconsistencyException',
// reason: 'I expected 49, but I got: 48.000000!'
My guess is, that it has something to do with CGFloat being a float on 32Bit and a double on 64Bit – and with the presumed use of the ceil within CGRectIntegral.
Is it a bug in Apple's code?
How can I fix this....elegantly?
Related
I am trying to use fftTap from iOS microphone with AudioKit, and here is the code
fft = FFTTap(highPassFilter2!, bufferSize: 8192 * 4, fftValidBinCount: nil, handler: {data in})
I tried using a bufferSize of 8192 * 4, which has allowed me to detect HZ at intervals of about 1.3
(Sample Rate is 44100, 44100 / (8192 * 4) = 1.34582519531, am I correct ?)
but I always get the exception error in File BaseTap around line 90.
private func handleTapBlock(buffer: AVAudioPCMBuffer, at time: AVAudioTime) {
// Call on the main thread so the client doesn't have to worry
// about thread safety.
buffer.frameLength = bufferSize <<<<< here
The log shows
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: length <= _imp->_frameCapacity'
terminating with uncaught exception of type NSException
It seems not work, but I want to be able to capture the accuracy less than 2 Hz, is there any way to try?
Really Thanks.
I am trying to find out maximum value from an array using #"#max.self" but it is returning nil when I try to run it on iOS 9.3.5 device, for the Higher version it works properly and returns the proper value.
NSNumber *maxOfBarGraphValues = [arrayOfBarGraphValues valueForKeyPath:#"#max.self"];
NSLog(#"%#",[[arrayOfBarGraphValues valueForKeyPath: #"#max.self"]floatValue] );
Below I am attaching output for the NSLog statement and value of arrayOfBarGraphValues from the console.
Printing description of self->arrayOfBarGraphValues: <__NSArrayM 0x16e1ffc0>
(
5,
4,
7,
7,
6,
6,
7,
7,
7,
7,
7,
7,
7
)
(lldb) po maxOfBarGraphValues
nil
Follow this code hope will helpful to you.
NSArray * arrayOfBarGraphValues = #[#5, #4, #7 ,#7 , #6, #6 ,#7 ,#7 ,#7 ,#7 ,#7 ,#7 ,#7 ];
int maxOfBarGraphValues = [[arrayOfBarGraphValues valueForKeyPath: #"#max.self"] intValue];
NSLog(#" MaximumValue Of BarGraph = %d", maxOfBarGraphValues);
Output:- // Maximum = 7
I have an irregular crash (1 in 5 times on devices, 4 in 5 times on Simulator). I have set an exception breakpoint and it occurs on the following line without any console information:
if let carColorSet = car.carToDisplay?.allObjects as? [Display] {
Note: car.carToDisplay is an NSSet
Before I set the exception breakpoint, I would get the following info in the console when it crashed:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableSet unionSet:]: set argument is not an NSSet'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102e79b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001023d6141 objc_exception_throw + 48
2 CoreFoundation 0x0000000102e00051 -[NSMutableSet unionSet:] + 1041
3 CoreData 0x0000000101b10df8 -[_NSFaultingMutableSet willReadWithContents:] + 936
4 CoreData 0x0000000101af131b -[_NSFaultingMutableSet allObjects] + 27
5 Keyboard 0x00000001018f838e
Any idea here? It seems like the crash occurs when I try to turn that carToDisplay?.allObjects into an array of Display objects.
This is a keyboard extension app btw.
Thank you for any input!
Problem (probably):
if let carColorSet = car.carToDisplay?.allObjects as? [Display]
carToDisplay is a NSet
However the function allObjects returns an array
I think you are trying to do a unionSet with an array.
Update the Question:
Please update your question, the qestion doesn't state the correct line of error.
The question needs to do the following
state where the unionSet is invoked.
what the argument type of unionSet is.
When I am trying to adjust of stack size of threads:
- (void)testStack:(NSInteger)n {
NSThread *thread = [[NSThread alloc]initWithTarget:self selector:#selector(dummy) object:nil];
NSUInteger size = 4096 * n;
[thread setStackSize:size];
[thread start];
}
- (void)dummy {
NSUInteger bytes = [[NSThread currentThread] stackSize];
NSLog(#"%#", #(bytes));
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
for (NSInteger i = 126; i <= 130; i++) {
[self testStack:i];
}
return YES;
}
in the output, the size is not changed:
2015-06-19 11:05:06.912 Stack[52982:2082454] 524288
2015-06-19 11:05:06.913 Stack[52982:2082457] 524288
2015-06-19 11:05:06.913 Stack[52982:2082456] 524288
2015-06-19 11:05:06.913 Stack[52982:2082458] 524288
2015-06-19 11:05:06.913 Stack[52982:2082455] 524288
is the iPhone stack size fixed?
p.s. I am testing the above in iPhone 6 Plus, debug mode.
UPDATE: the stack can be adjusted when running in the Simulator on MacBook:
2015-06-19 11:25:17.042 Stack[1418:427993] 528384
2015-06-19 11:25:17.042 Stack[1418:427994] 532480
2015-06-19 11:25:17.042 Stack[1418:427992] 524288
2015-06-19 11:25:17.042 Stack[1418:427991] 520192
2015-06-19 11:25:17.042 Stack[1418:427990] 516096
The stack size is bounded on the device, and in most cases cannot exceed 1MB for the main thread on iPhone OS, nor can it be shrunk.
The minimum allowed stack size for secondary threads is 16 KB and the stack size must be a multiple of 4 KB. The space for this memory is set aside in your process space at thread creation time, but the actual pages associated with that memory are not created until they are needed.
Actually you can set it. I am not sure if this changed with iOS 10, but on iOS 10.2.1 this does work. The only limitation is that the stack size has to be a multiple of 4kb.
pthread_attr_t tattr;
int ret = pthread_attr_init ( &tattr ) ;
size_t size;
ret = pthread_attr_getstacksize(&tattr, &size);
printf ( "Get: ret=%d,size=%zu\n" , ret , size ) ;
size = 4096 * 512 ;
ret = pthread_attr_setstacksize(&tattr, size);
int ret2 = pthread_attr_getstacksize(&tattr, &size);
printf ( "Set & Get: ret=%d ret2=%d,size=%zu\n" , ret , ret2 , size ) ;
Hello everyone I deployed an update for my app and few users have complained/bad reviews etc of app shutting down on them.
One user sent me a crash report and I have re-symbolicated it and it has shown the method where it is crashing and the line number.
I have tried many possible solutions but for the life of me I cannot reproduce it on my device.
Could anyone please be kind and let me know what could be the problem in the following code that is crashing the app:
The line no it is crashing is m:555 i.e
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:#{NSFontAttributeName: font}];
I am not sure what the issue is, I have tried passing #"" empty as content still it doesn't crashes.
-(CGFloat)getCellHeightForContent:(NSString*)content
{
NSString *text = content;
CGFloat width = self.tableview.frame.size.width - 15 - 30 - 15; //tableView width - left border width - accessory indicator - right border width
UIFont *font = [UIFont systemFontOfSize:17];
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:#{NSFontAttributeName: font}];
CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX}
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGSize size = rect.size;
size.height = ceilf(size.height);
size.width = ceilf(size.width);
if ((size.height )+ 5 < 70) {
return 70;
}
return size.height + 15;
}
here is the crash report
Incident Identifier: CAB2B27B-F65F-4F8A-82C6-C1AECD791335
CrashReporter Key: 759ffd08fa781ee7b8ae9515835758c563110d7f
Hardware Model: iPhone5,1
Process: xxxx [9226]
Path: /var/mobile/Applications/AA5E7A52-ED1E-421F-B377-CF32D55E71EA/xxxx.app/xxxx
Identifier: com.xxxx.xxxx
Version: 7.0.1 (7.0.1)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2014-06-18 22:09:44.336 -0400
OS Version: iOS 7.1.1 (11D201)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x2e33bf06 0x2e267000 + 872198
1 libobjc.A.dylib 0x38ad2ce2 0x38acf000 + 15586
2 CoreFoundation 0x2e33be48 0x2e267000 + 872008
3 Foundation 0x2ec72bd0 0x2ec57000 + 113616
4 Foundation 0x2ec72aac 0x2ec57000 + 113324
5 xxxx 0x00073850 -[DetailVC getCellHeightForContent:] (DetailVC.m:555)
6 xxxx 0x000725b4 -[DetailVC tableView:heightForRowAtIndexPath:] (DetailVC.m:382)
7 UIKit 0x30c7b1ae 0x30b60000 + 1159598
8 UIKit 0x30c3fd92 0x30b60000 + 916882
9 UIKit 0x30c41b6c 0x30b60000 + 924524
10 UIKit 0x30c41ac0 0x30b60000 + 924352
11 UIKit 0x30c416ba 0x30b60000 + 923322
12 xxxx 0x00070c4c -[DetailVC viewDidLoad] (DetailVC.m:157)
13 UIKit 0x30b6fa4e 0x30b60000 + 64078
14 UIKit 0x30b6f80c 0x30b60000 + 63500
15 UIKit 0x30cfbc0e 0x30b60000 + 1686542
16 UIKit 0x30c1948a 0x30b60000 + 758922
......
Thank you in advance for your help!!
Since the crash report is not fully symbolicated and the exception reason is not shown in the report, the following is only an assumption:
You are saying line 555 references this code:
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:#{NSFontAttributeName: font}];
This causing an exception could be because text is nil.
You should really try to get a fully symbolicated crash report. This requires your Mac to have the iOS symbols of iOS 7.1.1 of armv7s or armv7. You get those symbols by connecting an iPhone 5 or iPad 3 with iOS 7.1.1 running to your Mac. If you can't do that, provide the full crash report somewhere and I'll symbolicate it for you this one time.
Even better if you get a crash report that also shows the exception reason, but usually Apple reports do not contain that, so it might be helpful to integrate a 3rd party crash reporting functionality into your app. (Don't ask for recommendations since I am biased and most answers will also be biased, rather test them yourself and choose wisely).