Skip to content

Commit 1a0bd3b

Browse files
authored
Merge pull request #1221 from mapbox/preview-to-play-destroy-immediate-fix
Fix for `Destroying object multiple times. Don't use DestroyImmediate…
2 parents 28e9a78 + 788f049 commit 1a0bd3b

File tree

2 files changed

+28
-79
lines changed

2 files changed

+28
-79
lines changed

sdkproject/Assets/Mapbox/Examples/2_AstronautGame/AstronautGame.unity

+21-70
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ MonoBehaviour:
195195
m_Script: {fileID: 11500000, guid: cd961b1c9541a4cee99686069ecce852, type: 3}
196196
m_Name:
197197
m_EditorClassIdentifier:
198-
_initializeOnStart: 0
199198
_options:
200199
locationOptions:
201200
latitudeLongitude: 37.784179, -122.401583
@@ -204,7 +203,7 @@ MonoBehaviour:
204203
extentType: 0
205204
defaultExtents:
206205
cameraBoundsOptions:
207-
camera: {fileID: 0}
206+
camera: {fileID: 234181019}
208207
visibleBuffer: 0
209208
disposeBuffer: 0
210209
rangeAroundCenterOptions:
@@ -224,13 +223,14 @@ MonoBehaviour:
224223
unityTileSize: 100
225224
loadingTexture: {fileID: 2800000, guid: e2896a92727704803a9c422b043eae89, type: 3}
226225
tileMaterial: {fileID: 2100000, guid: b9f23e9bce724fa4daac57ecded470b8, type: 2}
226+
_initializeOnStart: 0
227227
_imagery:
228228
_layerProperty:
229229
sourceType: 2
230230
sourceOptions:
231231
isActive: 1
232232
layerSource:
233-
Name: Streets
233+
Name: Dark
234234
Id: mapbox://styles/mapbox/dark-v9
235235
Modified:
236236
UserName:
@@ -323,6 +323,10 @@ MonoBehaviour:
323323
combineMeshes: 0
324324
lineGeometryOptions:
325325
Width: 1
326+
MiterLimit: 0.2
327+
RoundLimit: 1.05
328+
JoinType: 1
329+
CapType: 1
326330
filterOptions:
327331
_selectedLayerName: building
328332
filters: []
@@ -340,7 +344,7 @@ MonoBehaviour:
340344
colliderType: 0
341345
materialOptions:
342346
style: 0
343-
texturingType: 0
347+
texturingType: 2
344348
materials:
345349
- Materials:
346350
- {fileID: 2100000, guid: 0f9e3de68a3085e469bd62c8b40e9487, type: 2}
@@ -382,6 +386,10 @@ MonoBehaviour:
382386
combineMeshes: 0
383387
lineGeometryOptions:
384388
Width: 1
389+
MiterLimit: 0.2
390+
RoundLimit: 1.05
391+
JoinType: 1
392+
CapType: 1
385393
filterOptions:
386394
_selectedLayerName: landuse
387395
filters: []
@@ -399,7 +407,7 @@ MonoBehaviour:
399407
colliderType: 2
400408
materialOptions:
401409
style: 0
402-
texturingType: 0
410+
texturingType: 2
403411
materials:
404412
- Materials:
405413
- {fileID: 2100000, guid: dd22d0eb52da4594e90fbb4dd7ae0baf, type: 2}
@@ -443,6 +451,10 @@ MonoBehaviour:
443451
combineMeshes: 0
444452
lineGeometryOptions:
445453
Width: 1
454+
MiterLimit: 0.2
455+
RoundLimit: 1.05
456+
JoinType: 1
457+
CapType: 1
446458
filterOptions:
447459
_selectedLayerName: road
448460
filters:
@@ -505,7 +517,7 @@ MonoBehaviour:
505517
colliderType: 0
506518
materialOptions:
507519
style: 0
508-
texturingType: 0
520+
texturingType: 2
509521
materials:
510522
- Materials:
511523
- {fileID: 0}
@@ -539,71 +551,10 @@ MonoBehaviour:
539551
presetFeatureType: 1
540552
_maskValue: 0
541553
selectedTypes:
542-
- coreOptions:
543-
sourceId:
544-
isActive: 0
545-
sublayerName: b2
546-
geometryType: 3
547-
layerName: building
548-
snapToTerrain: 1
549-
combineMeshes: 0
550-
lineGeometryOptions:
551-
Width: 1
552-
filterOptions:
553-
_selectedLayerName: building
554-
filters: []
555-
combinerType: 0
556-
extrusionOptions:
557-
_selectedLayerName: building
558-
extrusionType: 0
559-
extrusionGeometryType: 0
560-
propertyName: height
561-
propertyDescription: Number. Height of building or part of building.
562-
minimumHeight: 3
563-
maximumHeight: 0.2
564-
extrusionScaleFactor: 1
565-
colliderOptions:
566-
colliderType: 0
567-
materialOptions:
568-
style: 0
569-
texturingType: 0
570-
materials:
571-
- Materials:
572-
- {fileID: 0}
573-
- Materials:
574-
- {fileID: 0}
575-
atlasInfo: {fileID: 0}
576-
lightStyleOpacity: 1
577-
darkStyleOpacity: 1
578-
colorStyleColor: {r: 1, g: 1, b: 1, a: 1}
579-
samplePalettes: 0
580-
colorPalette: {fileID: 0}
581-
customStyleOptions:
582-
texturingType: 0
583-
materials:
584-
- Materials:
585-
- {fileID: 0}
586-
- Materials:
587-
- {fileID: 0}
588-
atlasInfo: {fileID: 0}
589-
colorPalette: {fileID: 0}
590-
performanceOptions:
591-
isEnabled: 1
592-
entityPerCoroutine: 20
593-
honorBuildingIdSetting: 1
594-
buildingsWithUniqueIds: 0
595-
moveFeaturePositionTo: 0
596-
MeshModifiers:
597-
- {fileID: 11400000, guid: 4fe5c136889ae0347af431be7e59e489, type: 2}
598-
- {fileID: 11400000, guid: b432bf85b0df280468dcfdaf5a9b90d0, type: 2}
599-
- {fileID: 11400000, guid: 4dbdd9c4bb7ba4d41ac1b710cf40de49, type: 2}
600-
GoModifiers:
601-
- {fileID: 11400000, guid: cd82d41d9097fef4fb5dafaebde20bfa, type: 2}
602-
presetFeatureType: 0
603-
_maskValue: 0
604-
selectedTypes:
605554
locationPrefabList: []
606555
_tileProvider: {fileID: 0}
556+
_previewOptions:
557+
isPreviewEnabled: 0
607558
--- !u!114 &159634026
608559
MonoBehaviour:
609560
m_ObjectHideFlags: 0
@@ -916,7 +867,7 @@ Prefab:
916867
- target: {fileID: 224857786874416376, guid: 98be219873e6d4dffb5949746f515a33,
917868
type: 2}
918869
propertyPath: m_AnchoredPosition.y
919-
value: 0
870+
value: 0.000015258789
920871
objectReference: {fileID: 0}
921872
- target: {fileID: 114731470950229392, guid: 98be219873e6d4dffb5949746f515a33,
922873
type: 2}

sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs

+7-9
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,16 @@ protected virtual void OnDestroy()
464464
}
465465
_mapVisualizer.ClearMap();
466466
_mapVisualizer.Destroy();
467-
if (_previewOptions.isPreviewEnabled == true)
468-
{
469-
DisableEditorPreview();
470-
}
471467
}
472468

473469
protected virtual void Awake()
474470
{
475-
MapOnAwakeRoutine();
476-
477471
if (_previewOptions.isPreviewEnabled == true)
478472
{
473+
DisableEditorPreview();
479474
_previewOptions.isPreviewEnabled = false;
480475
}
476+
MapOnAwakeRoutine();
481477
}
482478

483479
protected virtual void Start()
@@ -492,8 +488,6 @@ private void MapOnAwakeRoutine()
492488
{
493489
Destroy(tr.gameObject);
494490
}
495-
//Destroy default tileproviders that might be orphaned due to serialization.
496-
DestroyTileProvider();
497491

498492
// Setup a visualizer to get a "Starter" map.
499493
_mapVisualizer = ScriptableObject.CreateInstance<MapVisualizer>();
@@ -549,7 +543,10 @@ public void DisableEditorPreview()
549543
_vectorData.SubLayerAdded -= OnVectorDataSubLayerAdded;
550544
_vectorData.UpdateLayer -= OnVectorDataUpdateLayer;
551545
_vectorData.UnbindAllEvents();
552-
_mapVisualizer.ClearMap();
546+
if(_mapVisualizer != null)
547+
{
548+
_mapVisualizer.ClearMap();
549+
}
553550
DestroyTileProvider();
554551

555552
if (OnEditorPreviewDisabled != null)
@@ -564,6 +561,7 @@ public void DestroyTileProvider()
564561
if (_options.extentOptions.extentType != MapExtentType.Custom && tileProvider != null)
565562
{
566563
tileProvider.Destroy();
564+
_tileProvider = null;
567565
}
568566
}
569567

0 commit comments

Comments
 (0)