johnno1962 / InjectionLite

Swift package re-write of InjectionIII app
MIT License
39 stars 2 forks source link

Infinite loop after failed injection #4

Closed FelixLisczyk closed 1 year ago

FelixLisczyk commented 1 year ago

Hi,

Thanks for the great package! I've noticed an endless loop in my terminal. When InjectionLite fails to inject my changes, it retries the compilation every few seconds. That doesn't happen with the standalone InjectionIII.app. Here is an excerpt from my terminal:

πŸ”₯ Recompiling SourceFile.swift
πŸ”₯ ⚠️ dlopen failed dlopen(~/Library/Developer/CoreSimulator/Devices/3344ADB7-20E3-4F13-BE6C-CCCEF11161FA/data/Containers/Data/Application/2CC47149-6736-4148-879F-2430EFFF2942/tmp/eval1.dylib, 0x0002): symbol not found in flat namespace '_$s7SwiftUI5ColorV9TinyViewsE11desaturated8newValueACSd_tFfA_'
πŸ”₯ Recompiling SourceFile.swift
πŸ”₯ ⚠️ dlopen failed dlopen(~/Library/Developer/CoreSimulator/Devices/3344ADB7-20E3-4F13-BE6C-CCCEF11161FA/data/Containers/Data/Application/2CC47149-6736-4148-879F-2430EFFF2942/tmp/eval2.dylib, 0x0002): symbol not found in flat namespace '_$s7SwiftUI5ColorV9TinyViewsE11desaturated8newValueACSd_tFfA_'
πŸ”₯ Recompiling SourceFile.swift
πŸ”₯ ⚠️ dlopen failed dlopen(~/Library/Developer/CoreSimulator/Devices/3344ADB7-20E3-4F13-BE6C-CCCEF11161FA/data/Containers/Data/Application/2CC47149-6736-4148-879F-2430EFFF2942/tmp/eval3.dylib, 0x0002): symbol not found in flat namespace '_$s7SwiftUI5ColorV9TinyViewsE11desaturated8newValueACSd_tFfA_'
πŸ”₯ Recompiling SourceFile.swift
πŸ”₯ ⚠️ dlopen failed dlopen(~/Library/Developer/CoreSimulator/Devices/3344ADB7-20E3-4F13-BE6C-CCCEF11161FA/data/Containers/Data/Application/2CC47149-6736-4148-879F-2430EFFF2942/tmp/eval4.dylib, 0x0002): symbol not found in flat namespace '_$s7SwiftUI5ColorV9TinyViewsE11desaturated8newValueACSd_tFfA_'

Notice that eval1.dylib is incremented with each iteration. (eval2.dylib, eval3.dylib, etc.) Is this expected behavior?

johnno1962 commented 1 year ago

Hi, this isn't expected behaviour. It can happen when your code compiles but does not load with InjectionLite and it keeps retrying. I'm traveling at the moment and won't be able to fix it for a few weeks. If it's bothering you remove this line from your clone of the project but that doesn't solve the underlying problem which is related to trying to inject code that uses a default value for a function parameter newValue. Either expand out the parameter from its default or use one of the bundles from the InjectionIII app which is the more supported option and has additional code to handle this situation (a.k.a. unhiding).

default argument 0 of (extension in TinyViews):SwiftUI.Color.desaturated(newValue: Swift.Double) -> SwiftUI.Color
johnno1962 commented 1 year ago

I've pushed a quick patch to prevent the infinite loop but it is untested if you want to give it a try. To prevent the dlopen failure using the default argument of the desaturated() function, either expand out the default argument or use the InjectionIII app. Let me know how you get on.

FelixLisczyk commented 1 year ago

Thank you very much for your advice!

I've pushed a quick patch to prevent the infinite loop but it is untested if you want to give it a try.

Yes, this fix stops the loop after two iterations.

To prevent the dlopen failure using the default argument of the desaturated() function, either expand out the default argument

That works, thank you!

or use the InjectionIII app.

The InjectionIII app (version 4.7.2) produces a similar error message but no infinite loop.

πŸ’‰ Compiling SourceFile.swift
πŸ’‰ Selecting Xcode /Applications/Xcode-15.0.0-Beta.6.app/Contents/Developer
πŸ’‰ Loading .dylib ...
πŸ’‰ ⚠️ dlopen() error: dlopen(~/Library/Developer/CoreSimulator/Devices/3344ADB7-20E3-4F13-BE6C-CCCEF11161FA/data/Containers/Data/Application/611C8607-DCAC-4308-B157-966636045E3E/tmp/eval101.dylib, 0x0002): symbol not found in flat namespace '_$s7SwiftUI5ColorV9TinyViewsE11desaturated8newValueACSd_tFfA_'
πŸ’‰ ⚠️ Loading .dylib has failed, This is likely because Swift code being injected refers to a function with a default argument 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.

This is not a priority issue, and I can easily work around it. Please take your time and enjoy your trip. 😊

johnno1962 commented 1 year ago

Hi, the real solution here is to add the "unhide" functionality to this repo though as it only comes up only rarely, I'd like to keep this rep as straightforward as possible.