RDizzl3
RDizzl3

Reputation: 846

Debugging a EXC_BAD_ACCESS - Objective-C - Xcode 8.0

I am new to the objective-c realm and I am encountering a EXC_BAD_ACCESS. I know there are many forums and related content on stackoverflow - however I have still been unable to locate the source of my crash.

I have code to a game and when I exit a level and renter - the app crashes. Here are the steps that I have competed to try and located the source of the crash and the content that is displayed:

Image 1: enter image description here

Here are the associated messages respectively:

Image 2: enter image description here

Image 3: enter image description here

Image 4: enter image description here

Image 5: enter image description here

Image 6: enter image description here

I have enabled NSZombies and get this log when the app crashes:

Journey[76657:4493989] *** -[UILabel isKindOfClass:]: message sent to deallocated instance 0x60030b4d0d80. 

I have looked up this type of error but I am still unsure how to read it. Next I tried:

(lldb) command script import lldb.macosx.heap
"malloc_info", "ptr_refs", "cstr_refs", "find_variable", and "objc_refs" commands have been installed, use the "--help" options on these commands for detailed help.
(lldb) malloc_info --stack-history 0x60030b4d0d80

I read that this would help me determine the exact line in my code where the crash could be happening but the output didn't seem to match what I had in my code:

2016-11-02 19:47:47.338190 Casino Journey[76657:4498737] [] nw_socket_handle_socket_event Event mask: 0x4
2016-11-02 19:47:47.339741 Casino Journey[76657:4494204] [] tcp_connection_cancel 17
2016-11-02 19:47:47.346972 Casino Journey[76657:4498737] [] nw_socket_handle_socket_event Socket received WRITE_CLOSE event
2016-11-02 19:47:47.351492 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17 live.chartboost.com:443 ready resolver (satisfied)]
2016-11-02 19:47:47.358787 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.1 54.236.125.98:443 ready socket-flow (satisfied)]
2016-11-02 19:47:47.366406 Casino Journey[76657:4498737] [] __nw_socket_service_writes_block_invoke sendmsg(fd 13, 31 bytes): socket has been closed
2016-11-02 19:47:47.370392 Casino Journey[76657:4498737] [] nw_endpoint_flow_protocol_error [17.1 54.236.125.98:443 cancelled socket-flow (null)] Socket protocol sent error: [32] Broken pipe
2016-11-02 19:47:47.373586 Casino Journey[76657:4498737] [] nw_endpoint_flow_protocol_disconnected [17.1 54.236.125.98:443 cancelled socket-flow (null)] Output protocol disconnected
2016-11-02 19:47:47.376552 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.2 107.23.51.227:443 initial path (null)]
2016-11-02 19:47:47.380708 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.3 54.85.200.4:443 initial path (null)]
2016-11-02 19:47:47.383242 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.4 54.86.68.178:443 initial path (null)]
2016-11-02 19:47:47.385251 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.5 54.85.112.211:443 initial path (null)]
2016-11-02 19:47:47.387182 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.6 107.23.150.89:443 initial path (null)]
2016-11-02 19:47:47.388414 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.7 107.21.6.246:443 initial path (null)]
2016-11-02 19:47:47.389678 Casino Journey[76657:4498737] [] nw_endpoint_handler_cancel [17.8 54.210.97.43:443 initial path (null)]
2016-11-02 19:47:47.394671 Casino Journey[76657:4498737] [] nw_resolver_cancel_on_queue 0x6005eb89df70
2016-11-02 19:47:47.399258 Casino Journey[76657:4498737] [] -[NWConcrete_tcp_connection dealloc] 17
GuardMalloc[Casino Journey-76657]: Attempting excessively large memory allocation:  268435456 bytes
GuardMalloc[Casino Journey-76657]: If you really wanted to allocate so much memory, launch your executable with the environment variable MALLOC_PERMIT_INSANE_REQUESTS set to any value to circumvent this check.
GuardMalloc[Casino Journey-76657]: Explicitly trapping into debugger!!!
0x000060030b4d0d80: malloc(   640) -> 0x60030b4d0d80 _NSZombie_UILabel
error: expression failed "
typedef int kern_return_t;
typedef unsigned task_t;
#define MAX_FRAMES 128
#define MAX_HISTORY 16
typedef struct mach_stack_logging_record_t {
    uint32_t type_flags;
    uint64_t stack_identifier;
    uint64_t argument;
    uint64_t address;
} mach_stack_logging_record_t;
typedef void (*enumerate_callback_t)(mach_stack_logging_record_t, void *);
typedef struct malloc_stack_entry {
    uint64_t address;
    uint64_t argument;
    uint32_t type_flags;
    uint32_t num_frames;
    uint64_t frames[MAX_FRAMES];
    kern_return_t frames_err;    
} malloc_stack_entry;
typedef struct $malloc_stack_history {
    task_t task;
    unsigned idx;
    malloc_stack_entry entries[MAX_HISTORY];
} $malloc_stack_history;
$malloc_stack_history info = { (task_t)mach_task_self(), 0 };
uint32_t max_stack_frames = MAX_FRAMES;
enumerate_callback_t callback = [] (mach_stack_logging_record_t stack_record, void *baton) -> void {
    $malloc_stack_history *info = ($malloc_stack_history *)baton;
    if (info->idx < MAX_HISTORY) {
        malloc_stack_entry *stack_entry = &(info->entries[info->idx]);
        stack_entry->address = stack_record.address;
        stack_entry->type_flags = stack_record.type_flags;
        stack_entry->argument = stack_record.argument;
        stack_entry->num_frames = 0;
        stack_entry->frames[0] = 0;
        stack_entry->frames_err = (kern_return_t)__mach_stack_logging_frames_for_uniqued_stack (
            info->task, 
            stack_record.stack_identifier,
            stack_entry->frames,
            (uint32_t)MAX_FRAMES,
            &stack_entry->num_frames);
        // Terminate the frames with zero if there is room
        if (stack_entry->num_frames < MAX_FRAMES)
            stack_entry->frames[stack_entry->num_frames] = 0; 
    }
    ++info->idx;
};
(kern_return_t)__mach_stack_logging_enumerate_records (info.task, (uint64_t)0x60030b4d0d80, callback, &info);
info" => error: error: Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0).
The process has been returned to the state before expression evaluation.

If anyone could help me determine the possible source of this error I would really appreciate it! Any help or comments in general when trying to debug an error like this.

I am also using the newest version of xcode: Version 8.0

EDIT: I am adding the code for the BaseViewController - I do understand this might be hard to read and complex there are a lot of files with the actual code:

//
//
//

#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
#import "PHPublisherContentRequest.h"
#import <Foundation/Foundation.h>
#import "PHAPIRequest.h"
#import "PHContentView.h"
#import "AppController.h"
#import "Define.h"

@interface BaseViewController : UIViewController <SKProductsRequestDelegate, SKPaymentTransactionObserver, PHAPIRequestDelegate, PHPublisherContentRequestDelegate> {

    IBOutlet UIActivityIndicatorView *activityIndicator;
    BaseViewController *superClassDelegate;
}

- (void)exitIAP;
-(void) buyProductWithIdentifier:(NSString *) productIdentifier;
-(void) sendVgpCallToPlayHavenForPlacement:(NSString *) placementTag;


@end

Upvotes: 1

Views: 1049

Answers (3)

Shriram Kadam
Shriram Kadam

Reputation: 404

Please check once below things:-

  1. Go to TARGETS
  2. Select Build Phases
  3. Select Compile Sources
  4. Select your file/Class name
  5. Double click on Compiler Flags

Enter one word in box -fno-objc-arc

After enter -fno-objc-arc once clean & build your application.

Upvotes: 2

wei
wei

Reputation: 4727

As @New16 said, variables should be released before setting to nil.

If I were you, I would have a look UILabel in your BaseViewController.

Upvotes: 1

matt
matt

Reputation: 535138

I am new to the objective-c realm

Welcome to Objective-C. Here's the best advice you'll ever get:

USE ARC!!!

Really. The compiler knows much more about memory management than you do. Use ARC and lose all those retains, releases, and deallocs. Do it now.

Upvotes: 2

Related Questions