分段故障11,Xcode 8.2.1,Swift 3

时间:2017-02-15 02:41:20

标签: ios swift xcode segmentation-fault

我正在尝试创建应用程序的存档,但是在构建iOS设备时我遇到了分段错误。构建模拟器时我没有遇到这个问题。到目前为止,我有:

  • 清理我的项目
  • 清理我的构建文件夹
  • 删除了我的衍生数据文件夹
  • 已安装的Mac OS Sierra
  • 更新到Sierra
  • 后安装了其他Xcode工具
  • 多次重启Xcode / computer

错误通常如下所示:

a

在堆栈转储中,有这一行:

Call parameter type does not match function signature!
0  swift                    0x000000010f4ab3ad PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010f4aab56 SignalHandler(int) + 790
2  libsystem_platform.dylib 0x00007fffb1b28bba _sigtramp + 26
3  libsystem_platform.dylib 0x000000011033a000 _sigtramp + 1585517664
4  swift                    0x000000010f3038e8 llvm::TypeFinder::incorporateValue(llvm::Value const*) + 296
5  swift                    0x000000010f3032fa llvm::TypeFinder::run(llvm::Module const&, bool) + 682
6  swift                    0x000000010f1c827e (anonymous namespace)::TypePrinting::incorporateTypes(llvm::Module const&) + 30
7  swift                    0x000000010f1c9bdb printAsOperandImpl(llvm::Value const&, llvm::raw_ostream&, bool, llvm::ModuleSlotTracker&) + 171
8  swift                    0x000000010f30c633 (anonymous namespace)::VerifierSupport::Write(llvm::Value const*) + 67
9  swift                    0x000000010f31616e (anonymous namespace)::Verifier::VerifyCallSite(llvm::CallSite) + 590
10 swift                    0x000000010f318ef3 (anonymous namespace)::Verifier::visitCallInst(llvm::CallInst&) + 35
11 swift                    0x000000010f329ac1 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 1649
12 swift                    0x000000010f2e089d llvm::FPPassManager::runOnFunction(llvm::Function&) + 973
13 swift                    0x000000010f2e02ab llvm::FPPassManager::runOnModule(llvm::Module&) + 43
14 swift                    0x000000010f2e977a llvm::legacy::PassManager::run(llvm::Module&) + 1514
15 swift                    0x000000010c605901 performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef) + 5921
16 swift                    0x000000010c6038c1 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 2625
17 swift                    0x000000010c4b8f31 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23777
18 swift                    0x000000010c4b12b3 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17859
19 swift                    0x000000010c46d5cf main + 8239
20 libdyld.dylib            0x00007fffb191b255 start + 1

我认为这表明在编译静态计算变量2. Running pass 'Module Verifier' on function '@_TZFC12MyAppName23MyClassNameg13nextImagePathV10Foundation3URL' 时会抛出错误,该变量将nextImagePath返回到文件路径。在内部,这依赖于一些其他计算变量和方法URL。总而言之,代码如下所示:

nextFilePathForDirectoryAtURL

我不确定为什么会出现这种错误,或者为什么在为模拟器构建时不会发生这种错误。我现在一直试图找到大约5个小时的答案而没有运气,所以我想过去发帖。任何帮助是极大的赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

Welp,经过几个小时,我能够推断出错误是由documentSetDirectory计算变量引起的。显然,编译器不乐意将try语句的结果转换为可选语句。相反,我必须将语句包装在do catch块中。以下代码修复了我的问题:

fileprivate static var documentSetDirectory: URL {
  let directory = libraryDirectory.appendingPathComponent("MemberDocumentSets");

  do {
    try FileManager.default.createDirectory(
      at: directory,
      withIntermediateDirectories: true,
      attributes: nil);
  } catch {

    /* 
     * Do nothing. So why have a catch block at all? Because: for some reason
     * this prevents the compiler from spitting up. Apparently it didn't like
     * converting the `try` to an optional here. Weirdly, I'm still doing the
     * optional conversion elsewhere in this same class without issue (see
     * computed variables below).
     *
     * ¯\_(ツ)_/¯
     */
  }

  return directory;
}

fileprivate static var imageDirectory: URL {
  let directory = documentSetDirectory.appendingPathComponent("Images");

  try? FileManager.default.createDirectory(
    at: directory,
    withIntermediateDirectories: true,
    attributes: nil);

  return directory;
}

显然,这必定是编译器的错误。我创建了一个空项目并复制了原始代码,但它编译没有问题,我无法找到导致相同错误的任何项目设置差异。无论如何,我很高兴找到了解决方案,希望将来能为一些可怜的灵魂节省一些时间。