Debugging Issue

Hi team - I’m building an app and really struggling with an error, which I just can’t get my head around. I’ve managed to understand basic breakpoints, but my debugging skills currently don’t go any further than that.

My app runs a list, which grabs data from Firebase. Occasionally, when scrolling, the app will crash and I’ll get the message “Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1bc17ae78)”. This pops up next to @main in the very first file of the app.

When I look at the debugger, the last message is always the following (or similar):

2023-01-30 23:20:01.229663+0000 Cleek-SwiftUI[4518:1649528] [VKDefault] Missing MeshRenderables for ground mesh layer for (1/1) of ground tiles. Tile debug info: (Key: 2046.1362.12.255 t:34 kt:0, Has mesh errors: 0, MeshInstance count: 57, PendingMaterial count: 57, Invisible MeshInstances count: 0)

Would you have any ideas what is causing this? Nothing seems to be coming up on Google. If not - it looks to me like I’ve only scratched the surface on debugging, so if there’s more I need to know and you can point me to any material, that would be hugely appreciated.

This is a great tutorial about breakpoints to also check out

This seems like an unrelated error, have you added a breakpoint where you’re actually grabbing data from Firebase, and that succeeds and you get the right data??

(Are you using Firebase Storestore, or the Real Time Database?)

Thanks very much for this Mikaela - I had a watch of the video, which was helpful, although I still can’t seem to find the issue.

I’ve tried turning on an exception breakpoint, but this doesn’t seem to stop the app before the error.

The error happens on scrolling, but I can’t find the actual line in order to add a specific breakpoint. The issue is that scrolling works most of the time, but after a few scrolls (maybe 30 or so), the error comes up.

I use Firestore, and also Firebase Auth and Firebase Storage. The feed downloads images from storage based on references in Firsestore. It could be these methods causing the issue, but equally could be the UI (e.g. my List objects).

I’ve been trying to trace the stack as was done at the end of the video, but the error shows up in the AppDelegate by @main. When I go through the thread, I see that the last two bits are called “#0 0x00000001bc17ae78 in ___lldb_unnamed_symbol67219 ()” and “#32 0x00000001bc189750 in ___lldb_unnamed_symbol67524 ()”

Any ideas? Really appreciate your help with this, which has been baffling me!

Can you paste your code where you’re fetching the data from Firebase?

Paste your code in as text, rather than providing a screenshot.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key). You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.

Sure - it’s an events app that’s pulling events from an Events model that drive the Firestore queries. This is the method in the model:

    func getAllEvents() {
        
        db.collection("Events").whereField("inviteeUids", arrayContainsAny: [userUid, "openToAll"]).whereField("eventDate", isGreaterThanOrEqualTo: Date()).order(by: "eventDate", descending: true).addSnapshotListener { snapshot, error in
            
            if error == nil && snapshot != nil {
                
                let documents = snapshot?.documents
                
                if let documents = documents {
                    
                    var array = [CleekEvent]()
                    
                    for doc in documents {
                        
                        let docData = doc.data()
                        
                        let e = eventHelper.createEvent(data:docData)
                        if e != nil {
                            
                            if e?.organiserUid != self.userUid {
                                
                                array.insert(e!, at: 0)
                                
                            }
                            
                        }
                        
                    }
                    
                        self.eventsArray = array
                                                            
                }
                
            }
            
        }
        
    }

When you put a breakpoint on this line:

self.eventsArray = array you’re getting back the proper data, right?

(Or you can also just print array right here)

Yup - my array of events shows up when I print it. And the feed functions perfectly well for a while, until it crashes after a few scrolls up and down…

1 Like

Is it possibly my main/appdelegate struct is causing the issue? I get an error next to @main sometimes that says “Modifying state during view update, this will cause undefined behavior.” I have a feeling this may be to do with the Firestore methods which they ask you to include. Code below.

import SwiftUI
import FirebaseCore

class AppDelegate: NSObject, UIApplicationDelegate {
  func application(_ application: UIApplication,
                   didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    FirebaseApp.configure()

    return true
  }
}

@main
struct Cleek_SwiftUIApp: App {
    
    @StateObject var userAuthenticationService = UserModel()
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    
    var body: some Scene {
        WindowGroup {
            LaunchView()
                .environmentObject(userAuthenticationService)
        }
    }
}

No this is most likely not the issue. This is default code for how to configure Firebase in any app

When are you calling getAllEvents()?

Also scroll up in the console when it crashes and usually that has more info about the crash, than at the bottom of the console

Also crashing at main usually is just cause “the app is running,” cause everything runs from main, but it isn’t the source of the crash