Questions tagged [exc-bad-access]

EXC_BAD_ACCESS is a fatal error related to memory management on macOS and iOS.

This is a kind of crash that occurs when a program tries to access memory (including, but by no means limited to, Objective-C objects) that it has deallocated or had never allocated in the first place.

The correct name is EXC_BAD_ACCESS, not EXEC; the “EXC” stands for “exception”, specifically a Mach kernel exception (meaning that the kernel did not like what your process did; this is not the same as a kernel panic). This isn't a C++ or Objective-C exception, so there's no catching it.

EXC_BAD_ACCESS means that you've freed or released an object and then tried to use it later, or failed to retain an object that you planned to use again later.

To prevent this error from happening:

  • Practice good memory management
  • Run the static analyzer in Xcode to find bugs
  • Run Instruments with the Zombies template to find premature-object-death bugs
2059 questions
10
votes
1 answer

My App calls scrollViewDidScroll 19 times

I have an app based on Apple's PageControl sample. The first time the view loads, the scroll view is loaded with page 0 and page 1. Whenever a scroll is initiated, the scrollViewDidScroll method should get called by UIKit correct? When initiating a…
joec
  • 3,533
  • 10
  • 60
  • 89
10
votes
2 answers

NSMutableDictionary inside JSONModel - EXC_BAD_ACCESS KERN_INVALID_ADDRESS

Crashlytics reported this crash in one of my apps and I am not able to reproduce it at all, no matter what I do. This happens to about 5% of the users, so it's a pretty big deal. I'm posting screenshots with the crash report and also the methods…
stonycis
  • 466
  • 4
  • 16
9
votes
3 answers

Assigning an existing CGColor to a CGColor property works in iOS Simulator, not iOS device. Why?

I know how to fix the problem that I am about to outline, however, I am a bit baffled as to why the code scenario works in the iOS simulator but not on my iPad. I have a method that checks various properties, and then sets the background color of a…
RLH
  • 15,230
  • 22
  • 98
  • 182
9
votes
3 answers

DCRoundSwitch gives EXC_BAD_ACCESS when using ARC

I'm using DCRoundSwitch for a project where I basically need an UISwitch where I'm able to edit its label contents. Because I'm using ARC I refactored the DCRoundSwitch code to be ARC-compatible in xcode. When compiling and running in the simulator…
dimme
  • 4,393
  • 4
  • 31
  • 51
9
votes
2 answers

UIAlertView shown from background thread and with no delegate creates EXC_BAD_ACCESS

Here is my code: #ifdef DEBUG UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"JSON Parsing Error" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; [alertView…
Mick F
  • 7,312
  • 6
  • 51
  • 98
9
votes
3 answers

OpenGL ES EXC_BAD_ACCESS on glDrawArrays

I'm having an issue rendering in OpenGL ES 1.1 for an iPhone game that I'm building. In short, I am rendering 3 items: Background (works fine) A number of spherical objects (works fine) A simple line circle that changes size (I am getting a problem…
paynio
  • 111
  • 4
  • 10
9
votes
4 answers

EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash

My app has been running fine in debugging mode through Xcode, but whenever it's downloaded through TestFlight, it crashes with this error: EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000200013f7b9e78. It's crashing at this line. I see specialized…
slider
  • 2,736
  • 4
  • 33
  • 69
9
votes
2 answers

Subclassing Swift Generic Class with NSObject inheritance

I'm running into an error where I'm not certain if it's a limitation of the Swift language, or a bug. Here's the most basic premise: class GenericClass : NSObject { var inputValue: T init(value: T) { self.inputValue = value …
erendiox
  • 91
  • 4
9
votes
1 answer

EXC_BAD_ACCESS when updating Swift dictionary after using it for evaluate NSExpression

I'm using a dictionary to evaluate an expression, when the expression has variables and the dictionary is actually used by NSExpression, something happens and I get EXC_BAD_ACCESS when trying to update the dictionary, this only happens when…
juanelomx
  • 251
  • 3
  • 4
9
votes
2 answers

NSURLSession invalidateAndCancel: Bad Access

I have a strange problem when I try to invalidate an NSURLSession instance. The code is quite simple: I have a View Controller, two buttons (start: and stop:), and a text field for the url. A simple extract of the code: - (IBAction)start:(id)sender…
LombaX
  • 17,265
  • 5
  • 52
  • 77
8
votes
2 answers

Crash on ImageLoaderMachO on app loading on iPhone

I'm getting a crash when the app load from the debugger ( EXC_BAD_ACCESS ), on this line (asm): __dyld__ZN16ImageLoaderMachO12bindLocationERKN11ImageLoader11LinkContextEmmPKS0_hPKclS7_+320> I understand it has something with image loader, but I…
taxman
  • 501
  • 11
  • 21
8
votes
2 answers

Re-Assigning instance of AVAudioPlayer in iOS13 leads to BAD_ACCESS runtime error

I have an app, that is for many years in the AppStore and runs without any crashes (last deployment target iOS 12.4). I have some code for playing a sound on certain events in the app. Now I tried to upgrade my app for iOS 13 and without changing…
LukeSideWalker
  • 7,399
  • 2
  • 37
  • 45
8
votes
1 answer

XCode 4 Not Breaking On Correct Line on EXC_BAD_ACCESS

I recently had my xcode upgraded to version 4, and I have an EXC_BAD_ACCESS exception in my code, but despite setting NSZombieEnabled in the environment it's still showing the break point on the thread1, int retVal = UIApplicationMain(argc, argv,…
Ray Price
  • 81
  • 1
  • 2
8
votes
0 answers

EXC_BAD_ACCESS when creating CIContext on iOS8.1 but not 9 or 10

I am getting exc_bad_access on the line CIContext *context = [CIContext contextWithOptions:nil]; I have enabled zombies and checked with instruments: No luck. The full code is: - (UIImage *) doBinarize:(UIImage *)sourceImage…
CodemanDoEl
  • 472
  • 1
  • 4
  • 18
8
votes
1 answer

EXC_BAD_ACCESS(code=1, address=0x10) on Core Data Fetch

I'm getting an intermittent bug that is proving very hard to debug. I'm getting the following error from the following method EXC_BAD_ACCESS(code=1, address=0x10) on Core Data Fetch class func getAll(context: NSManagedObjectContext) -> [Tag] { …
Unome
  • 6,750
  • 7
  • 45
  • 87