johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 565 forks source link

Application crashes after swizzling code! #59

Closed haashem closed 8 years ago

haashem commented 8 years ago

my application crashes after swizzling code with no reason!

console log:

2015-09-23 19:36:36.093 MyProject[35105:2370479] Injection attempting connection to: 127.0.0.1:31442
2015-09-23 19:36:36.096 MyProject[35105:2370479] Connected to "Injection" plugin, ready to load x86_64 code.
Compiling /Users/hashem/Desktop/Xcode Projects/MyProject/MyProject/RestMenuPageViewController.m
2015-09-23 19:36:36.336 MyProject[35105:2370377] Swizzled RestMenuPageViewController 0x113bdd7e8 -> 0x101ac7450

I deleted app from simulator but no success.

I tested with other apps. code injection works well for them!

do you have any idea?

johnno1962 commented 8 years ago

Could be anything but probably to so with static variables which can confuse your code or possibly https://github.com/johnno1962/injectionforxcode/issues/35. You’re not adding ivars or anything?

haashem commented 8 years ago

I have used some static variables in the header file. do you think that would be because of that? static const CGFloat kButtonMargin adding static instant variable? no, no where

johnno1962 commented 8 years ago

Where does it crash - or is it no particular place?

haashem commented 8 years ago

I have set breakpoint for all exception. but it crashes at the main.m file main method!

johnno1962 commented 8 years ago

You’ll have to put in a whole bunch of NSLogs until you track it down I’m afraid. Do you think the injection completes and then it crashes somewhere else? Subscribe to notification @"INJECTION_BUNDLE_NOTIFICATION"

haashem commented 8 years ago

thanks for your quick response subscribing to that notification doesn't rise any event! I should partially track my code to find crash origin.

you can set issue as resolved!

johnno1962 commented 8 years ago

Patch your project’s main.m (Project/Injection Plugin/Patch Project for Injection) and you should get better debugging info. Good Luck!

haashem commented 8 years ago

SOLVED! praise god! you are a man that never give up!
thanks for your hint. I was observing an object without unregistering it in dealloc method! An instance 0x7faa69f78d40 of class FlexibleHeader was deallocated while key value observers were still registered with it.

johnno1962 commented 8 years ago

Excellent!