From d70596934f3652dbf9e05026032f39997d2399e5 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 17 Oct 2024 14:08:46 +0200 Subject: [PATCH] Update SentryReplayApi.m --- Sources/Sentry/SentryReplayApi.m | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Sources/Sentry/SentryReplayApi.m b/Sources/Sentry/SentryReplayApi.m index 3aad160229..6efe38ffb7 100644 --- a/Sources/Sentry/SentryReplayApi.m +++ b/Sources/Sentry/SentryReplayApi.m @@ -39,20 +39,25 @@ - (void)resume - (void)start { - SentrySessionReplayIntegration *replayIntegration + // Start could be misused and called multiple times, causing it to + // be initialized more than once before being installed. + // Synchronizing it will prevent this problem. + @synchronized (self) { + SentrySessionReplayIntegration *replayIntegration = (SentrySessionReplayIntegration *)[SentrySDK.currentHub - getInstalledIntegration:SentrySessionReplayIntegration.class]; - - if (replayIntegration == nil) { - SentryOptions *currentOptions = SentrySDK.currentHub.client.options; - replayIntegration = + getInstalledIntegration:SentrySessionReplayIntegration.class]; + + if (replayIntegration == nil) { + SentryOptions *currentOptions = SentrySDK.currentHub.client.options; + replayIntegration = [[SentrySessionReplayIntegration alloc] initForManualUse:currentOptions]; - - [SentrySDK.currentHub addInstalledIntegration:replayIntegration - name:NSStringFromClass(SentrySessionReplay.class)]; + + [SentrySDK.currentHub addInstalledIntegration:replayIntegration + name:NSStringFromClass(SentrySessionReplay.class)]; + } + + [replayIntegration start]; } - - [replayIntegration start]; } - (void)stop