@@ -61,13 +61,11 @@ internal delegate void GADUAdsExhaustedForPreloadIdCallback(IntPtr interstitialA
6161 public InterstitialAdPreloaderClient ( )
6262 {
6363 _interstitialAdPreloaderClientPtr = ( IntPtr ) GCHandle . Alloc ( this ) ;
64- InterstitialAdPreloaderPtr = Externs . GADUCreateInterstitialAdPreloader ( _interstitialAdPreloaderClientPtr ) ;
65-
66- Externs . GADUSetInterstitialAdPreloaderCallbacks (
67- InterstitialAdPreloaderPtr ,
68- AdAvailableForPreloadIdCallback ,
69- AdFailedToPreloadForPreloadIdCallback ,
70- AdsExhaustedForPreloadIdCallback ) ;
64+ InterstitialAdPreloaderPtr = Externs . GADUCreateInterstitialAdPreloader (
65+ _interstitialAdPreloaderClientPtr ,
66+ AdAvailableForPreloadIdCallback ,
67+ AdFailedToPreloadForPreloadIdCallback ,
68+ AdsExhaustedForPreloadIdCallback ) ;
7169 }
7270
7371 public bool Preload ( string preloadId , PreloadConfiguration preloadConfiguration ,
@@ -90,18 +88,30 @@ public bool Preload(string preloadId, PreloadConfiguration preloadConfiguration,
9088 {
9189 preloadConfigurationClient . Request = preloadConfiguration . Request ;
9290 }
91+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
92+ {
93+ return false ;
94+ }
9395 return Externs . GADUInterstitialAdPreloaderPreload ( InterstitialAdPreloaderPtr , preloadId ,
9496 preloadConfigRef ) ;
9597 }
9698
9799 public bool IsAdAvailable ( string preloadId )
98100 {
101+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
102+ {
103+ return false ;
104+ }
99105 return Externs . GADUInterstitialAdPreloaderIsAdAvailable ( InterstitialAdPreloaderPtr ,
100106 preloadId ) ;
101107 }
102108
103109 public IInterstitialClient DequeueAd ( string preloadId )
104110 {
111+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
112+ {
113+ return null ;
114+ }
105115 var interstitialAdClient = new InterstitialClient ( ) ;
106116 var interstitialAdClientPtr = ( IntPtr ) GCHandle . Alloc ( interstitialAdClient ) ;
107117 var interstitialAd = Externs . GADUInterstitialAdPreloaderGetPreloadedAd (
@@ -114,12 +124,20 @@ public IInterstitialClient DequeueAd(string preloadId)
114124
115125 public int GetNumAdsAvailable ( string preloadId )
116126 {
127+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
128+ {
129+ return 0 ;
130+ }
117131 return Externs . GADUInterstitialAdPreloaderGetNumAdsAvailable ( InterstitialAdPreloaderPtr ,
118132 preloadId ) ;
119133 }
120134
121135 public PreloadConfiguration GetConfiguration ( string preloadId )
122136 {
137+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
138+ {
139+ return null ;
140+ }
123141 var config = Externs . GADUInterstitialAdPreloaderGetConfiguration (
124142 InterstitialAdPreloaderPtr , preloadId ) ;
125143 if ( config == IntPtr . Zero )
@@ -140,6 +158,10 @@ public PreloadConfiguration GetConfiguration(string preloadId)
140158 public Dictionary < string , PreloadConfiguration > GetConfigurations ( )
141159 {
142160 var configurations = new Dictionary < string , PreloadConfiguration > ( ) ;
161+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
162+ {
163+ return configurations ;
164+ }
143165 var configurationsPtr = Externs . GADUInterstitialAdPreloaderGetConfigurations ( InterstitialAdPreloaderPtr ) ;
144166 // Marshall the Dictionary from configurationsPtr
145167 var marshalledConfigurations =
@@ -161,11 +183,19 @@ public Dictionary<string, PreloadConfiguration> GetConfigurations()
161183
162184 public void Destroy ( string preloadId )
163185 {
186+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
187+ {
188+ return ;
189+ }
164190 Externs . GADUInterstitialAdPreloaderDestroy ( InterstitialAdPreloaderPtr , preloadId ) ;
165191 }
166192
167193 public void DestroyAll ( )
168194 {
195+ if ( InterstitialAdPreloaderPtr == IntPtr . Zero )
196+ {
197+ return ;
198+ }
169199 Externs . GADUInterstitialAdPreloaderDestroyAll ( InterstitialAdPreloaderPtr ) ;
170200 }
171201
0 commit comments