InjectionIII icon indicating copy to clipboard operation
InjectionIII copied to clipboard

Crash on reload every time

Open everlof opened this issue 1 year ago • 6 comments

Hi,

While developing I suddenly couldn't use it anymore as it crashes on every reload. I know I can't modify the memory but I get crashes even by just changing this:

rootStackView.spacing = 20

to

rootStackView.spacing = 10

How can I debug this? I just crash with Thread 1: EXC_BAD_ACCESS (code=1, address=0x28)

Here's the stacktrace of the crash:

  * frame #0: 0x000000011c105c2c eval101.dylib`CalendarView.hasHeader.getter(self=0x00000001127efc40) at CalendarView.swift:47:30
    frame #1: 0x000000011c106a9c eval101.dylib`CalendarView.setup(self=0x00000001127efc40) at CalendarView.swift:100:12
    frame #2: 0x000000011c105718 eval101.dylib`CalendarView.init(date=2024-02-01 22:59:59 UTC, period=month) at CalendarView.swift:24:9
    frame #3: 0x000000011c105494 eval101.dylib`CalendarView.__allocating_init(date:period:) at CalendarView.swift:0

everlof avatar Feb 01 '24 09:02 everlof

Hi, I'm wondering if this is a problem where a static singleton var is getting uninitialised. Without seeing your code I can't say much more. Let me know if you would like to TeamView.

johnno1962 avatar Feb 01 '24 09:02 johnno1962

If that would help identifying it, surely! How do we communicate that credentials?

everlof avatar Feb 01 '24 10:02 everlof

Maybe some additional info when running with some diagnostics:

💉 ⚠️ Loading .dylib has failed, This is likely because Swift code being injected references a function using a default argument or a member with access control that is too restrictive or perhaps an XCTest that depends on code not normally linked into your application. Rebuilding and re-running your project (without a build clean) can resolve this.
💉 Loading .dylib ...
💉 ⚠️ dlopen() error: dlopen(/Users/d/Library/Developer/CoreSimulator/Devices/EDFBEFFC-81AE-4D67-BF2A-1BD9B6719A1C/data/Containers/Data/Application/53ACE3EE-77EE-4F35-AAB0-43178F1D101C/tmp/eval104.dylib, 0x0002): symbol not found in flat namespace '___asan_option_detect_stack_use_after_return'
💉 ⚠️ Loading .dylib has failed, This is likely because Swift code being injected references a function using a default argument or a member with access control that is too restrictive or perhaps an XCTest that depends on code not normally linked into your application. Rebuilding and re-running your project (without a build clean) can resolve this.

everlof avatar Feb 01 '24 11:02 everlof

You can email your details to github at johnholdsworth.com.

johnno1962 avatar Feb 01 '24 11:02 johnno1962

Hm, thanks, but maybe solved it myself. Your comment static singleton var is getting uninitialised. got me thinking.

Could this be caused by Calendar.autoupdatingCurrent perhaps?

Changing this:

calendarLogic = CalendarLogic(calendar: .autoupdatingCurrent, currentDate: date, period: period)

to

calendarLogic = CalendarLogic(calendar: .init(identifier: .gregorian), currentDate: date, period: period)

doesn't crash in the same location it seems.

everlof avatar Feb 01 '24 12:02 everlof

Yes, when you inject, your static/top level vars get reinitialised as they live in the memory of the object file that has been injected. You can change this behaviour if you prefer by setting environment variable INJECTION_PRESERVE_STATICS then references to top level variables will always refer to their first definition. i.e. they won't get set to zero/nil. Happy you've sorted this out!

johnno1962 avatar Feb 01 '24 12:02 johnno1962