Skip to content

Resolved memory consumption issue, Your app was consuming too much memory and did crash for lengthy recording #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>StrayScanner debug.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<key>StrayScanner.xcscheme_^#shared#^_</key>
<dict>
Expand Down
Binary file not shown.
23 changes: 22 additions & 1 deletion StrayScanner/Controllers/RecordSessionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class RecordSessionViewController : UIViewController, ARSessionDelegate {
@IBOutlet private var timeLabel: UILabel!
@IBOutlet weak var fpsButton: UIButton!
var dismissFunction: Optional<() -> Void> = Optional.none
var datasetResetTimer: Timer?
var lastSavedFrameNumber: Int = 0 // ✅ Keeps track of frames across resets


func setDismissFunction(_ fn: Optional<() -> Void>) {
self.dismissFunction = fn
Expand Down Expand Up @@ -163,9 +166,27 @@ class RecordSessionViewController : UIViewController, ARSessionDelegate {
updateLabelTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
self.updateTime()
}
startRawIMU()

datasetEncoder = DatasetEncoder(arConfiguration: arConfiguration!, fpsDivider: FpsDividers[chosenFpsSetting])
startRawIMU()

datasetResetTimer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) { _ in
guard let datasetEncoder = self.datasetEncoder else { return }

datasetEncoder.wrapUp() // ✅ Save current data and close files
self.lastSavedFrameNumber = datasetEncoder.savedFrames // ✅ Store last saved frame number

// ✅ Create a new dataset encoder but continue frame numbering
self.datasetEncoder = DatasetEncoder(arConfiguration: self.arConfiguration!,
fpsDivider: FpsDividers[self.chosenFpsSetting],
startFrame : self.lastSavedFrameNumber)
print("DatasetEncoder reset, continuing from frame \(self.lastSavedFrameNumber)")

//If you want to record for a certain period of time programmatically, i.e. want your recording to stop after lets say 5min, then uncomment the following lines
// Timer.scheduledTimer(withTimeInterval: 300.0, repeats: false) { _ in
// self.stopRecording()
// }
}
}

private func stopRecording() {
Expand Down
7 changes: 5 additions & 2 deletions StrayScanner/Helpers/DatasetEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class DatasetEncoder {
private var lastFrame: ARFrame?
private var dispatchGroup = DispatchGroup()
private var currentFrame: Int = -1
private var savedFrames: Int = 0
private let frameInterval: Int // Only save every frameInterval-th frame.
public let id: UUID
public let rgbFilePath: URL // Relative to app document directory.
Expand All @@ -35,13 +34,17 @@ class DatasetEncoder {
public let odometryPath: URL
public let imuPath: URL
public var status = Status.allGood
public var savedFrames: Int // ✅ Now it can be set externally
private let queue: DispatchQueue

private var latestAccelerometerData: (timestamp: Double, data: simd_double3)?
private var latestGyroscopeData: (timestamp: Double, data: simd_double3)?




init(arConfiguration: ARWorldTrackingConfiguration, fpsDivider: Int = 1) {
init(arConfiguration: ARWorldTrackingConfiguration, fpsDivider: Int = 1, startFrame: Int = 0) {
self.savedFrames = startFrame // ✅ Use externally set frame number
self.frameInterval = fpsDivider
self.queue = DispatchQueue(label: "encoderQueue")

Expand Down