Exc_Bad_Instruction Only in iPhone 5 Simulator

EXC_BAD_INSTRUCTION only in iPhone 5 simulator

NSInteger (which is a type alias for Int in Swift) is a 32-bit
integer on 32-bit platforms like the iPhone 5.
The result of

NSInteger(NSDate().timeIntervalSince1970) * 1000

is 1480106653342 (at this moment) and does not fit into the
range -2^31 ... 2^31-1 of 32-bit (signed) integers.
Therefore Swift aborts the execution. (Swift does not "truncate"
the result of integer arithmetic operations as it is done in some
other programming languages, unless you specifically use the
"overflow" operators like &*.)

You can use Int64 for 64-bit computations on all platforms:

Int64(NSDate().timeIntervalSince1970 * 1000)

In your case, if a string is needed:

let lastLogin = String(Int64(NSDate().timeIntervalSince1970 * 1000))

what does Error “Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)” mean?

It means that there there are instructions that lead to a crash, such as force unwrapping something that doesn't exist, and getting a value of nil.

Take a look through your code and see if there are any situations where you force unwrap something that does not necessarily exist.

EXC_BAD_INSTRUCTION at performSelector

Try using the selector directly, and make surecallback: is a valid method of self.delegate:

dispatch_async(dispatch_get_main_queue(), ^(void) 
{
    [self.delegate performSelector:@selector(callback:) withObject:self];
});

Another debugging tip is to set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

Replace 0x543216 with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.

See this article for more detailed instructions.

objc_copyClassList: crash EXC_BAD_INSTRUCTION after update to iOS 13.4 / XCode 11.4

Just noticed: classList is a total misnomer. The returned result has type AutoreleasingUnsafeMutablePointer<AnyClass>?. Convert it to an UnsafeBufferPointer<AnyClass> first, and then do your processing on that:

func getSubclassInfos() -> [ClassInfo] {
let superObject = CityModel.self
let superClassInfo = ClassInfo(superObject)

var count = UInt32(0)
guard let classListPointer = objc_copyClassList(&count) else { return [] }

return UnsafeBufferPointer(start: classListPointer, count: Int(count))
.map(ClassInfo.init)
.filter { $0 == superClassInfo }
}

KingFisher 5.0 crashing with EXC_BAD_INSTRUCTION in Xcode 11.2

UPDATE: As per twitter the solution to this and similar problems with Swift Package Manager in Xcode 11.2 is to go to the target, "Linker settings" and change "Dead Code Stripping" to NO

There is an open issue in Github. The issue is around the Package Manager in Xcode 11.2 They will need to update the linker for the Package Manager.



Related Topics



Leave a reply



Submit