3

I released a simple game which works fine on iPhone 5s, 6, 6s and iPads. But when running on iPhone 5, 5c, 4S or 4, the app crashes at the point when this code happens:

let delay = Int(arc4random_uniform(UInt32(300)))*Int(NSEC_PER_SEC)/100

I get this error:

thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0)

I think it's really weird it only happens on iPhone 5 and below.

Gregg Bursey
  • 1,097
  • 2
  • 11
  • 16
Bram Roelandts
  • 470
  • 7
  • 25

2 Answers2

6

The maximum value of a 32 bits integer is 2 147 483 647.

Your delay value may be greater than that, so sometimes it will crash on 32 bits platforms like these devices you listed because Int won't be able to hold the value.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
3

If the reason is because the Int cant hold the value then make it a UInt. This will double its maximum value.

Arbitur
  • 38,684
  • 22
  • 91
  • 128