googlevr / gvr-ios-sdk

Google VR SDK for iOS
http://developers.google.com/vr/ios/
Other
647 stars 191 forks source link

Huge lags, cardboard not working, memory leaks in 0.9.0 #115

Closed uranpro closed 8 years ago

uranpro commented 8 years ago

Huge lags

When I play ~5 videos in 1 GVRVideoView its start lagging very hard.

Cardboard not working

Trying to resolve lags(1) I start creating videoView for each URL. Cardboard working fine only first time, next tries will show black screen. I think there is a memory leaks...

Memory leaks in 0.9.0

When I saw cardboard problems(2), I checked GVRVideoView for memory leaks:

1) create GVRVideoView and load some video from URL 2) wait until video starts 3) remove GVRVideoView from superview 4) GVRVideoView is not deallocated (can see in profiler Instruments->Leaks)

// ...
@property (nonatomic, strong) GVRVideoView *videoView;
// ...

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createVideoView];
}

- (void)createVideoView {
    if (self.videoView) {
        [self.videoView removeFromSuperview];
        [self setVideoView:nil];
    }

    self.videoView = [[GVRVideoView alloc] initWithFrame:CGRectZero];
    self.videoView.delegate = self;
    self.videoView.enableTouchTracking = YES;
    self.videoView.enableCardboardButton = YES;
    self.videoView.displayMode = kGVRWidgetDisplayModeEmbedded;
    self.videoView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addSubview:self.videoView];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_videoView]|"
                                                                      options:NSLayoutFormatDirectionLeadingToTrailing
                                                                      metrics:nil
                                                                        views:NSDictionaryOfVariableBindings(_videoView)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_videoView]|"
                                                                      options:NSLayoutFormatDirectionLeadingToTrailing
                                                                      metrics:nil
                                                                        views:NSDictionaryOfVariableBindings(_videoView)]];

    [self.videoView loadFromUrl:[NSURL URLWithString:@"https://xxxxxxx/xxxx.mp4"]];
}

#pragma mark - GVRVideoViewDelegate

- (void)widgetViewDidTap:(GVRWidgetView *)widgetView {
    [self createVideoView];
}
nathanmartz commented 8 years ago

Thanks for the bug report. This is a known issue that we're working on.

rainerjungwirth commented 8 years ago

You can put the GVRVideoView Object in a singleton Class then you can play multiple videos without issues. The following solutions in swift is working for me

class GVFix{
    static var sharedInstance = GVRVideoView()
    private init(){}
}

class GoogleViewController: UIViewController {
  override func viewDidLoad() {
        super.viewDidLoad()

            GVFix.sharedInstance.resume()
            GVFix.sharedInstance.frame = CGRectMake(0, 0, view.frame.width, view.frame.height)
            GVFix.sharedInstance.enableCardboardButton = false
            GVFix.sharedInstance.enableFullscreenButton = false
            GVFix.sharedInstance.loadFromUrl("https://xxxxxxx/xxxx.mp4", ofType: GVRVideoType.Mono)
            GVFix.sharedInstance.displayMode = GVRWidgetDisplayMode.FullscreenVR
            GVFix.sharedInstance.delegate = self
            view.addSubview(GVFix.sharedInstance)
        }

  override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        GVFix.sharedInstance.stop()
        GVFix.sharedInstance.removeFromSuperview()
 }
}
r3trosteve commented 8 years ago

@rainerjungwirth good shout, this works well for now at least to prevent the crashing I was experiencing time and again....

r3trosteve commented 8 years ago

Actually, as a follow up, the Singleton approach helps resolve some memory issues (I still get a warning) when rendering the video in the non-cardboard view, but when I switch to cardboard fullscreen mode, my app crashes (on device) with error:

Message from debugger: Terminated due to memory issue

Edit: just realised I'm running 0.8.5 of GVRSDK, updating pod now to test with any later version...

Edit: OK, now running 0.9.0 and confirm same issue when loading Cardboard View.

My sample video is ~880MB in stereo format Also verified same result with ~220MB in mono format

r3trosteve commented 8 years ago

Blush. I killed some UIImage animations and haven't had an issue with the VRView player since.

nathanmartz commented 8 years ago

Well, glad you got it fixed :)

uranpro commented 8 years ago

@nathanmartz it fix only cardboard issue! But not huge lags and memory leaks

nathanmartz commented 8 years ago

Sorry about that. I think at least the leaks will be fixed in our next update. We haven't had as much reproducing the lags.

sanjayc77 commented 8 years ago

Please try the latest GVRSDK 1.0.1.

https://github.com/CocoaPods/Specs/blob/master/Specs/GVRSDK/1.0.1/GVRSDK.podspec.json