App Crashing with VM - pmap_enter retried due to resource shortage

Hi, a few of my customers are facing a crash on using the app. I am unable to reproduce the issue myself. Can you please help. Here is the crash log of a user. Mine is a SwiftUI app.

Main exception is : VM - pmap_enter retried due to resource shortage

This VM - pmap_enter retried due to resource shortage message is almost always a red herring. The actual cause of your crash is an unhandled language exception. You can see the source of the Last Exception Backtrace section:

Last Exception Backtrace:
0   CoreFoundation  … __exceptionPreprocess + 164
1   libobjc.A.dylib … objc_exception_throw + 60
2   Foundation      … _userInfoForFileAndLine + 0
3   UIKitCore       … -[UICollectionView _validateScrollingTargetIndexPath:] + 412
4   UIKitCore       … -[UICollectionView _contentOffsetForScrollingToItemAtIndexPath:atScrollPosition:] + 52
5   UIKitCore       … -[UICollectionView _scrollToItemAtIndexPath:atScrollPosition:animated:] + 240
6   SwiftUI         … 0x1c435c000 + 8210516
7   SwiftUI         … 0x1c435c000 + 6680760
8   SwiftUI         … 0x1c435c000 + 5270420
9   AttributeGraph  … AG::Graph::UpdateStack::update() + 520
10  AttributeGraph  … AG::Graph::update_attribute(AG::data::ptr, unsigned int) + 424
11  AttributeGraph  … AG::Subgraph::update(unsigned int) + 844
12  SwiftUI         … 0x1c435c000 + 123524
13  SwiftUI         … 0x1c435c000 + 20883924
14  SwiftUI         … 0x1c435c000 + 10046968
15  SwiftUI         … 0x1c435c000 + 112896
16  SwiftUI         … 0x1c435c000 + 86912
17  SwiftUI         … 0x1c435c000 + 60748
18  SwiftUI         … 0x1c435c000 + 20883868
19  SwiftUI         … 0x1c435c000 + 20883592
20  SwiftUI         … 0x1c435c000 + 942096
21  SwiftUI         … 0x1c435c000 + 7329688
22  SwiftUI         … 0x1c435c000 + 7329864
23  UIKitCore       … _UIUpdateSequenceRun + 84
24  UIKitCore       … schedulerStepScheduledMainSection + 172
25  UIKitCore       … runloopSourceCallback + 92
26  CoreFoundation  … __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
…

Frame 26 is the main thread’s run loop handling an event source. That event source is something in UIKit (frames 25 through 23), which has then called out to SwiftUI (frames 22 through 6 [1]). That has called back into UIKit (frames 5 through 3), this time doing something related to UICollectionView scrolling. That’s detected a problem and thrown an exception.

Now, I’m not an expert on either SwiftUI or UIKit, so please take all of the rest of this with a grain of salt…

AFAICT frame 3 can throw in two different cases:

  • If the section in the index path you’re scrolling to is greater than the number of sections in the collection.

  • If the item index in the index path is greater than the number of items in that section.

If you were programming with UICollectionView directly my advice would be to look at your code to make sure that the index path is within bounds. However, you’re programming with SwiftUI, and I’d expect that to handle this stuff for you.

The crash report you posted is from iOS 16. Have you seen the same crash in iOS 17?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Frameworks 11 through 9 are in the AttributeGraph library, which is an implementation detail within SwiftUI.

Thank you. I myself am unable to reproduce this error. I have tried running it on simulators with 16.x but I do not get this exception. Two users who have reported this issue have following devices and OSs. The app is crashing during taking a quiz with question and answers (SwiftUI List). There is no direct use of UICollectionView in my code, although scrollToPosition is used to scroll when explanation for the answer appears.

Model: iPhone12,1. OS: 16.2

Model: iPhone15,3. OS: 16.3.1

Two users who have reported this issue have following devices and OSs.

Do you have a sense of your user distribution between iOS 16 and 17? Because both of those users are running iOS 16, which could mean that this is a bug that we fixed in OS 17.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Where can I see that? In "trends" I can only see by the metric "device", not "OS".

And here is the code


struct QuizContentView: View {
    @Binding var currentQuestionNumber: Int
    @Binding var expVisibility: Bool
    @ObservedObject  var dataManager: DataManager = DataManager.shared
    var onAnswerSelectedClosure: ((Int) -> Void)?
    var body: some View {
        if dataManager.currentQuiz.questionsForCurrentTest.count > 0 {
  
            ZoomableImageView(graphic:dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].content.graphic)
            ScrollViewReader { proxy in
                 List{
                    if (AppSettings.isTestingPhaseActive()){
                        Text(dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].id)
                    }

                    EmptyView().id("scrollToPos")
                  
                    QuestionTextView(text:dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].instruction, isInstruction: true)
                        .italicText()
                        .listRowInsets(EdgeInsets()) // Removes the default padding
                        .listRowBackground(Colors.questionBackground)

                    QuestionTextView(text:dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].processedQuestionText)
                        .listRowInsets(EdgeInsets()) // Removes the default padding
                        .listRowBackground(Colors.questionBackground)

                    if (AppSettings.isMultipleAnswerSelectionAllowed()){
                        PromptView(text: dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].prompt)
                            .listRowInsets(EdgeInsets()) // Removes the default padding
                            .listRowBackground(Colors.promptBackground)
                    }
                    
                    ForEach(dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].answers.indices, id:\.self) { index in
                        SingleAnswerView(text: dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].answers[index].content.text,
                                         graphic: dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].answers[index].content.graphic,
                                         fillColor: Colors.getAnswerColor(question: dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber],answerIndex: index,isReviewMode:dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].explanation.visibility)
                        ){
                            if (dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].explanation.visibility == false){
                                if let closure = onAnswerSelectedClosure {
                                    closure(index)
                                }
                            }
                        }
                        .id(index)
                    }//for each
                    if(dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].explanation.visibility ) {
                        ExplanationView(text:dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].explanation.content.text,
                                        graphic:dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].explanation.content.graphic, reference: dataManager.currentQuiz.questionsForCurrentTest[currentQuestionNumber].reference, fillColor: Colors.explanationBackground)

                    }
                }//list
                .listStyle(.plain) //to make entire screen white
                //MARK:scroll issue fix below with two .onChange methods, note expVisibility and explanation.visibility must be separate for reviewing
                .onChange(of: expVisibility) { [oldValue = expVisibility] newValue in
                    if oldValue == false && newValue == true {
                        withAnimation {
                            proxy.scrollTo("ExplanationLabel" , anchor: .bottomTrailing)
                        }
                    }
                }
                .onChange(of: currentQuestionNumber) { _ in
                    withAnimation {
                        proxy.scrollTo("scrollToPos", anchor: .topLeading) //first answer
                    }
                }
            }//scrollview reader of list
        }
    }
    
}

Where can I see that?

I figured you’d survey the crash report that look like this to see if any of them are from iOS 17.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thsi piece of code seems to be the issue. I asked the two users on whom the app is crashing, to turn of "instant feedback" feature off and the app is not crashing.

So it is the scrollTo option which is the issue. Can something be fixed in this so that it does not crash in 16.x OS?

                    if oldValue == false && newValue == true {
                        withAnimation {
                            proxy.scrollTo("ExplanationLabel" , anchor: .bottomTrailing)
                        }
                    }
                }
App Crashing with VM - pmap_enter retried due to resource shortage
 
 
Q