Skip to content

Commit b6b0fee

Browse files
committed
fix runtime tests
fix data fetching manager and cache manager to invoke callbacks in failures to complete the call change file cache and move file saving call into a try/catch block in case of IO failures add a basic nullcheck to vector layer module script for missing unity references fix jump method buttons in debug scene
1 parent 7d086e1 commit b6b0fee

File tree

7 files changed

+30
-32
lines changed

7 files changed

+30
-32
lines changed

Runtime/Mapbox/BaseModule/Data/DataFetchers/DataFetchingManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ private IEnumerator UpdateTick()
7878
{
7979
_fetchQueue.Dequeue();
8080
FetchCancelled(info);
81+
info.Callback(new DataFetchingResult() { State = WebResponseResult.Cancelled });
8182
continue;
8283
}
8384

Runtime/Mapbox/BaseModule/Data/Platform/Cache/FileCache.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,9 @@ public virtual HashSet<string> GetFileList()
189189
}
190190
}
191191
}
192-
193192
return pathList;
194193
}
195194

196-
197-
198195
protected virtual void SaveInfo(InfoWrapper info)
199196
{
200197
if (info.TextureCacheItem == null)
@@ -217,19 +214,26 @@ protected virtual void SaveInfo(InfoWrapper info)
217214
TilesetId = info.TextureCacheItem.TilesetId,
218215
Action = () =>
219216
{
220-
var fullPath = RelativeFilePathToFileInfoExpects(info.Path);
221-
FileStream sourceStream = new FileStream(
222-
RelativeFilePathToFileInfoExpects(info.Path),
223-
FileMode.Create, FileAccess.Write, FileShare.Read,
224-
bufferSize: 4096, useAsync: false);
225-
226-
sourceStream.Write(info.TextureCacheItem.Data, 0, info.TextureCacheItem.Data.Length);
227-
sourceStream.Close();
228-
229-
var finalRelativePath = FullFilePathToRelativePath(fullPath);
230-
info.PostSaveAction(finalRelativePath);
231-
//Debug.Log(string.Format("File saved {0} - {1}", info.TextureCacheItem.TileId, info.Path));
232-
OnFileSaved(info.TextureCacheItem, finalRelativePath);
217+
try
218+
{
219+
var fullPath = RelativeFilePathToFileInfoExpects(info.Path);
220+
FileStream sourceStream = new FileStream(
221+
RelativeFilePathToFileInfoExpects(info.Path),
222+
FileMode.Create, FileAccess.Write, FileShare.Read,
223+
bufferSize: 4096, useAsync: false);
224+
225+
sourceStream.Write(info.TextureCacheItem.Data, 0, info.TextureCacheItem.Data.Length);
226+
sourceStream.Close();
227+
228+
var finalRelativePath = FullFilePathToRelativePath(fullPath);
229+
info.PostSaveAction(finalRelativePath);
230+
//Debug.Log(string.Format("File saved {0} - {1}", info.TextureCacheItem.TileId, info.Path));
231+
OnFileSaved(info.TextureCacheItem, finalRelativePath);
232+
}
233+
catch (Exception e)
234+
{
235+
Debug.LogException(e);
236+
}
233237
},
234238
ContinueWith = (t) =>
235239
{

Runtime/Mapbox/BaseModule/Data/Platform/Cache/MapboxCacheManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public void SaveImage(RasterData textureCacheItem, bool forceInsert)
138138
}
139139
else
140140
{
141+
callback?.Invoke(null);
141142
return null;
142143
}
143144
}

Runtime/Mapbox/MapDebug/Scenes/LocationGame.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ MonoBehaviour:
373373
m_Calls:
374374
- m_Target: {fileID: 49602455}
375375
m_TargetAssemblyTypeName: EventTest, Assembly-CSharp
376-
m_MethodName: JumpSF
376+
m_MethodName: Jump
377377
m_Mode: 5
378378
m_Arguments:
379379
m_ObjectArgument: {fileID: 0}
@@ -1517,7 +1517,7 @@ MonoBehaviour:
15171517
m_Calls:
15181518
- m_Target: {fileID: 49602455}
15191519
m_TargetAssemblyTypeName: EventTest, Assembly-CSharp
1520-
m_MethodName: JumpSF
1520+
m_MethodName: Jump
15211521
m_Mode: 5
15221522
m_Arguments:
15231523
m_ObjectArgument: {fileID: 0}

Runtime/Mapbox/VectorModule/Unity/VectorLayerModuleScript.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public override ILayerModule ConstructModule(MapService service, IMapInformation
2626
var dictionary = new Dictionary<string, IVectorLayerVisualizer>();
2727
foreach (var visualizerObject in _layerVisualizers)
2828
{
29+
if(visualizerObject == null) continue;
2930
var visualizer = visualizerObject.ConstructLayerVisualizer(mapInformation, unityContext);
3031
dictionary.Add(visualizer.VectorLayerName, visualizer);
3132
}

Tests/Runtime/BaseModule/LocationGamePrefabTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public IEnumerator FindAndRegisterToMapNoInitialize()
3636
void OnMapCoreInitialized(MapboxMap mapboxMap)
3737
{
3838
_map = mapboxMap;
39-
_map.OnFirstViewCompleted += () => _firstViewLoaded = true;
39+
_map.LoadViewCompleted += () => _firstViewLoaded = true;
4040
Assert.IsNotNull(mapboxMap);
4141
}
4242

@@ -58,15 +58,15 @@ void OnMapCoreInitialized(MapboxMap mapboxMap)
5858
{
5959
if (mapboxMap == null) throw new ArgumentNullException(nameof(mapboxMap));
6060
_map = mapboxMap;
61-
_map.OnFirstViewCompleted += () => _firstViewLoaded = true;
61+
_map.LoadViewCompleted += () => _firstViewLoaded = true;
6262
Assert.IsNotNull(mapboxMap);
6363
}
6464

6565
_mapCore.Initialized += OnMapCoreInitialized;
6666

6767
_mapCore.Initialize();
6868

69-
while(_mapCore.InitializationStatus < InitializationStatus.ViewLoaded) yield return null;
69+
while(_mapCore.InitializationStatus < InitializationStatus.ReadyForUpdates) yield return null;
7070

7171
Assert.IsNotNull(_map);
7272
Assert.IsTrue(_map.Status > InitializationStatus.Initialized);

Tests/Runtime/BaseModule/MapboxMapTests.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,16 @@ public IEnumerator TileJson()
118118
}
119119

120120
[UnityTest]
121-
public IEnumerator LoadMapView()
121+
public IEnumerator LoadMapIntoMemory()
122122
{
123123
var mapLoaded = false;
124-
var firstViewCompletedEventFired = false;
125-
_map.OnFirstViewCompleted += () => { firstViewCompletedEventFired = true; };
126-
127124
var coroutine = Runnable.Instance.StartCoroutine(_map.LoadMapViewCoroutine(() =>
128125
{
129126
mapLoaded = true;
130127
}));
131128
while(mapLoaded == false) yield return null;
132129

133130
Assert.IsTrue(mapLoaded);
134-
Assert.IsTrue(firstViewCompletedEventFired);
135-
Assert.IsTrue(_map.Status > InitializationStatus.Initialized);
136-
Assert.IsNotEmpty(_map.TileCover.Tiles);
137131
}
138132

139133
[Test]
@@ -188,7 +182,6 @@ public IEnumerator VectorFetching()
188182
Assert.NotNull(tile);
189183
Assert.NotNull(tile.ByteData);
190184
Assert.IsNotEmpty(tile.ByteData);
191-
Assert.AreEqual(_datafetcher.TotalRequestCount, 0);
192185
}
193186

194187

@@ -201,13 +194,11 @@ public IEnumerator VectorFetchingCancelled()
201194
{
202195
isDone = true;
203196
}));
204-
Assert.AreEqual(_datafetcher.TotalRequestCount, 1);
205-
_datafetcher.CancelFetching(tile, _tilesetId);
197+
tile.Cancel();
206198
while (isDone == false) yield return null;
207199

208200
Assert.NotNull(tile);
209201
Assert.AreEqual(tile.CurrentTileState, TileState.Canceled);
210-
Assert.AreEqual(_datafetcher.TotalRequestCount, 0);
211202
}
212203
}
213204
}

0 commit comments

Comments
 (0)