1- using System . Collections . Generic ;
1+ using System . Collections . Concurrent ;
22using System . IO ;
33using System . Linq ;
44
@@ -27,7 +27,7 @@ public class AssetsFileInstance
2727 /// </summary>
2828 public BundleFileInstance parentBundle = null ;
2929
30- internal Dictionary < int , AssetsFileInstance > dependencyCache ;
30+ internal ConcurrentDictionary < int , AssetsFileInstance > dependencyCache ;
3131
3232 /// <summary>
3333 /// The stream the assets file uses.
@@ -43,7 +43,7 @@ public AssetsFileInstance(AssetsFile file, string filePath)
4343 path = Path . GetFullPath ( filePath ) ;
4444 name = Path . GetFileName ( path ) ;
4545 this . file = file ;
46- dependencyCache = new Dictionary < int , AssetsFileInstance > ( ) ;
46+ dependencyCache = new ConcurrentDictionary < int , AssetsFileInstance > ( ) ;
4747 }
4848
4949 public AssetsFileInstance ( Stream stream , string filePath )
@@ -52,7 +52,7 @@ public AssetsFileInstance(Stream stream, string filePath)
5252 name = Path . GetFileName ( path ) ;
5353 file = new AssetsFile ( ) ;
5454 file . Read ( new AssetsFileReader ( stream ) ) ;
55- dependencyCache = new Dictionary < int , AssetsFileInstance > ( ) ;
55+ dependencyCache = new ConcurrentDictionary < int , AssetsFileInstance > ( ) ;
5656 }
5757
5858 public AssetsFileInstance ( FileStream stream )
@@ -61,15 +61,19 @@ public AssetsFileInstance(FileStream stream)
6161 name = Path . GetFileName ( path ) ;
6262 file = new AssetsFile ( ) ;
6363 file . Read ( new AssetsFileReader ( stream ) ) ;
64- dependencyCache = new Dictionary < int , AssetsFileInstance > ( ) ;
64+ dependencyCache = new ConcurrentDictionary < int , AssetsFileInstance > ( ) ;
6565 }
6666
6767 public AssetsFileInstance GetDependency ( AssetsManager am , int depIdx )
6868 {
69- if ( ! dependencyCache . ContainsKey ( depIdx ) || dependencyCache [ depIdx ] == null )
69+ if ( ( ! dependencyCache . ContainsKey ( depIdx ) || dependencyCache [ depIdx ] == null ) )
7070 {
71- string depPath = file . Metadata . Externals [ depIdx ] . PathName ;
71+ if ( depIdx >= file . Metadata . Externals . Count )
72+ {
73+ return null ;
74+ }
7275
76+ string depPath = file . Metadata . Externals [ depIdx ] . PathName ;
7377 if ( depPath == string . Empty )
7478 {
7579 return null ;
0 commit comments