Crash-safe append() in Swift - ios

After updating to iOS 14 Developer Beta my app began crashing. Mainly it happens on line axis.entries.append(Double(f)) of the library which I use for creating charts. Here is the console output:
Fatal error: UnsafeMutablePointer.initialize overlapping range: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1200.2.19.2/swift/stdlib/public/core/UnsafePointer.swift, line 832
Fatal error: UnsafeMutablePointer.initialize overlapping range: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1200.2.19.2/swift/stdlib/public/core/UnsafePointer.swift, line 832
I don't believe I can fix this library, so I want a simple solution just to prevent my app from crashing. This line axis.entries.append(Double(f)) is being called multiple times without crashing, so what I want to do is to perform this append if it won't crash my app and don't perform append if it will. Is there a way to implement this?
I have tried putting this line inside try and if, but with no result.

Related

Attempting to deactivate a non-dynamic body

I am using Cocos2D 3.1 with SpriteBuilder and I am simply trying to get things working. I have set up my SpriteBuilder ccb with a physicsNode and put my physics objects within it.
In my app I then try to call this:
[_sprite.physicsBody applyImpulse:ccp(-95.0f, 2800.0f)];
All of a sudden, there is a SIGABRT and it crashes on this line in cpSpaceComponent.c:
cpAssertHard(cpBodyGetType(body) == CP_BODY_TYPE_DYNAMIC, "Internal error: Attempting to deactivate a non-dynamic body.");
Aborting due to Chipmunk error: Internal error: Attempting to
deactivate a non-dynamic body. Failed condition: cpBodyGetType(body)
== CP_BODY_TYPE_DYNAMIC
I have looked around and there is no documentation on this type of crash. I am not even sure where to begin to try to fix this. Does anyone know what I should do to fix this crash?
Fixed it. Turns out my CCPhysicsNode had a sleep time threshold of 0, once I set it to the normal .5, everything works fine.

How to know which line is causing exception?

I am new to XCode and Objective C. I have intentionally make a mistake to assign number to NSString*.
NSString* s = #1;
[s uppercaseString];
Though XCode gives me warning, this code will compile. But at runtime I get exception. Now I see in logs, (Sorry for image, I was not able to paste is as text properly due to formatting)
In this log, how I find exact place of error. How this log tells me which code to change.
So it looks like you are running the Release build (debug symbols stripped) and if you got that crash log in a production environment you would need to symbolicate it in order to find the line.
This Apple TN gives some details of Symbolication.
In a development environment you would simply add an exception breakpoint and run it from Xcode, as the debug symbols would not be stripped.
To understand what line causes the problem, you usually need to add exception breakpoint to your project as explained in this document;
In the bottom-left corner of the breakpoints navigator, click the
Add button.
Choose Add Exception Breakpoint.
In the Exception pop-up menu, choose the type of exception on which
you want execution to stop:
All. Stops on all exceptions.
Objective-C. Stops on Objective-C exceptions.
C++. Stops on C++ exceptions. To stop on a particular C++ exception, specify the exception name.
Choose the phase of the exception handling process at which you want program execution to stop.
Click Done.
line 5 Sam : [BIDViewController viewDidLoad] + 143 , if this is a release build , you need to resolve with symbols the memory address of the function , this is called "symbolize" the crash dump...
In the log look for your project name and you will come to know.
e.g.
line 5 Sam : [BIDViewController viewDidLoad] + 143
If you want to produce real crash without warning, try following code it will produce index out of bound exception and will crash
NSArray *array = #[#"1",#"2"];
NSLog(#"Item not accessible->%#",(NSString*)array[2]);
set Exception breaking point or enable NSZombie object
or
NSZombie
From the menu bar, choose Project > Scheme > Edit Scheme

ERROR: shrink of file system cache did not fully complete. Result: 21

its my first day using ios 7
i get this line in log hundreds of times per second.
i didn't get it before with the same code with iOS 6
maybe thats caused by :
[NSData dataWithContentsOfURL:(NSURL *)];
it does not happen when i remove this line
do anybody know what's the meaning of this error ?

build settings to generate proper dSYM

I have a question regarding dSYM. I made an experiment with my app and added following code to it:
if (currentMenuPage_ == MenuPageAttrsVals) {
return ((ValueAndId *) [currentValues_ objectAtIndex:-1]).name;
}
as expected application crashed and crash log was generated.
However Xcode and atos can not tell me exact line where the crash is.
2 CoreFoundation 0x3192c23d -[__NSArrayI objectAtIndex:] + 165
3 MyApp 0x00053487 0x49000 + 42119
4 MyApp 0x0005102d 0x49000 + 32813
Do I have to set some special settings when building my app to generate proper dSYM?
If I call dwarfdump --uuid MyApp.app.dSYM I get a number. Does this number should appear somewhere in my crash log?
That number should appear in the first line under the Binary Images section. (It might be formatted differently, e.g. lowercase and without the - chars).
Please remember, every time you do a build, this UUID changes, and if you did not save the previous dSYM, it won't symbolicate it.
If you did not change a lot (any) code, you could replace the UUID string in the Binary Images section (keep the format in there) with the new one from the latest dSYM.
If symbolication did not work, and the UUID is correct, that folder is most likely not indexed by Spotlight, so the symbolication script can't find the dSYM.

How to track down "incorrect checksum for freed object"

I have spent quite some time trying to trace this problem and read multiple suggestion from others with the same problem. I deal with a large code base so finding the problem without some hints is like looking for a needle in a hay stack.
On of the suggestion I read is to add a break point on *malloc_error_break* - but how do I do that. I understand that I have to add a symbolic break point but I'm not sure what exactly to enter in the two text fields, Symbol and Module?
I tried to enable Malloc Scribble and Malloc Guard Edges - but none of it results in any break point or crashes.
If I enable Zombie Objects the programs stops crashing but there is nothing in the output log showing any problems.
Finally I tried to enable Guard Malloc. I understand that it only works with the simulator so I tries that - but the problem is that the programs crashes in the start up phase before any line in my program is executed:
0x958e0cd4 <+0000> mov 0x4(%esp),%eax
0x958e0cd8 <+0004> mov %gs:0x0(,%eax,4),%eax < Crash
0x958e0ce0 <+0012> ret
and the call stack looks like this:
pthread_getspecific
__dyld__dyld_start
I'm not sure what I'm doing wrong here?
To add a breakpoint on malloc_error_break, simply stop in the debugger and type b malloc_error_break at the "gdb" or "lldb" prompt.

Resources