加载场景内存不足(display scene receive memory issue)

343
2
07-24-2019 02:27 AM
DanWang2
New Contributor

I am developing a 3D APP with ArcGIS Runtime SDK for iOS 100.5. I have tried the following 2 ways, but I always receive a "terminated due to memory issue" error.

1. Display my scene through scene server.

2. Display my scene through mobile scene package(.mspk).

Is there an effective way to display a scene in iOS APP?

0 Kudos
2 Replies
NimeshJarecha
Esri Regular Contributor

Hi Dan,

There are lot of samples available for 3D (Scene). Did you try them? Are you able to make them work on your device?

Samples Available on GitHub:

arcgis-runtime-samples-ios/arcgis-ios-sdk-samples/Scenes at master · Esri/arcgis-runtime-samples-ios... 

To investigate the issue you are seeing, can you post your code and stack trace here so we can look into it?

Regards,

Nimesh

0 Kudos
DanWang2
New Contributor

Thank you for your reply! I have done according to the official Demo in Github. Here is my code:

//mspk

- (void)addMspk:(FSDMspk *)mspk {

    

    NSString *path = [FSDUtility docPathForFile:mspk.fileName];

    NSURL *url = [NSURL fileURLWithPath:path];

    

    [AGSMobileScenePackage checkDirectReadSupportForMobileScenePackageAtFileURL:url

                                                                     completion:^(BOOL isDirectReadSupported, NSError * _Nullable error)

    {

        if (error) {

            DLog(@"验证mspk失败, error = %@", error.localizedDescription);

        } else if (isDirectReadSupported) {

            [self addMspkSceneWithFileUrl:url];

        } else {

             

            NSString *unpackPath = [FSDUtility cachePathForFile:mspk.fileName];

            NSURL *unpackUrl = [NSURL fileURLWithPath:unpackPath];

             

            if ([FSD_FILE_MANAGER fileExistsAtPath:unpackPath]) {

                [FSD_FILE_MANAGER removeItemAtPath:unpackPath error:nil];

            }

             

            [AGSMobileScenePackage unpackMobileScenePackageAtFileURL:url

                                                     outputDirectory:unpackUrl

                                                          completion:^(NSError * _Nullable error)

            {

                if (error) {

                    DLog(@"解包mspk失败!");

                } else {

                    [self addMspkSceneWithFileUrl:unpackUrl];

                }

            }];

        }

    }];

}

- (void)addMspkSceneWithFileUrl:(NSURL *)url {

    

    AGSMobileScenePackage *mspkLayer = [AGSMobileScenePackage mobileScenePackageWithFileURL:url];

    [mspkLayer loadWithCompletion:^(NSError * _Nullable error) {

        if (error) {

            DLog(@"加载mspk失败, error = %@", error.localizedDescription);

        } else {

            self.sceneView.scene = mspkLayer.scenes.firstObject;

            [self configMspkLayerInfo];

            

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                [self configInitialCamera];

            });

        }

    }];

}

//SceneServer

- (void)addOnlineLayer:(FSDLayer *)layer {

    

    if (FSD_STRING_EMPTY(layer.tileUrl)) return;

    

    NSString *urlStr = [NSString stringWithFormat:@"%@/layers/0", layer.tileUrl];

    DLog(@"SceneServer url = %@", urlStr);

    AGSArcGISSceneLayer *sceneLayer = [AGSArcGISSceneLayer ArcGISSceneLayerWithURL:[NSURL URLWithString:urlStr]];

    sceneLayer.name = layer.name;

    sceneLayer.layerID = [NSString stringWithFormat:@"%@_%@", layer.name, kLayerSuffixTile];

    sceneLayer.visible = layer.visible;

    

    [self.sceneView.scene.operationalLayers addObject:sceneLayer];

    

    AGSCamera *camera = [AGSCamera cameraWithLatitude:30.275955 longitude:120.0 altitude:500 heading:0 pitch:60 roll:0];

    [self.sceneView setViewpointCamera:camera];

    

    [sceneLayer loadWithCompletion:^(NSError * _Nullable error) {

        if (error) {

            DLog(@"%@加载失败, error = %@", layer.name, error.localizedDescription);

        } else {

            DLog(@"%@加载成功", layer.name);

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                if (!self.initialCamera) {

                    [self configInitialCamera];

                }

            });

        }

    }];

}

0 Kudos