Skip to content

Commit

Permalink
fixes a realm threading crash when importing roms into the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
proskd committed Nov 11, 2024
1 parent d5d423d commit 2ea4cf1
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class GameImporterDatabaseService : GameImporterDatabaseServicing {
if game.originalArtworkFile == nil {
game = await getArtwork(forGame: game)
}
self.saveGame(game)
await self.saveGame(game)
}

@discardableResult
Expand Down Expand Up @@ -485,10 +485,14 @@ class GameImporterDatabaseService : GameImporterDatabaseServicing {
}

/// Saves a game to the database
func saveGame(_ game:PVGame) {
func saveGame(_ game:PVGame) async {
do {
//TODO: this might crash if not on main thread - validate
let database = RomDatabase.sharedInstance
let realm = try! await RomDatabase.sharedInstance.realm

if let system = realm.object(ofType: PVSystem.self, forPrimaryKey: game.systemIdentifier) {
game.system = system
}
try database.writeTransaction {
database.realm.create(PVGame.self, value:game, update:.modified)
}
Expand Down

0 comments on commit 2ea4cf1

Please sign in to comment.