I’m trying to integrate PubCenter interstitial ads within my game.
I have set up an event in my mono behavior script named “AdManager” and calling it like:
public static event EventHandler CalledAds;
// called with UI button
private void ShowInterstitial()
{
if (CalledAds != null)
CalledAds(null, null);
}
and in the VS generated project in App.xaml.cs:
private InterstitialAd ads;
public App()
{
this.InitializeComponent();
appCallbacks = new AppCallbacks();
ads = new InterstitialAd();
ads.RequestAd(AdType.Video, appId, adUnitId);
}
private void AdManager_CalledAds(object sender, EventArgs e)
{
if (ads.State == InterstitialAdState.Ready)
ads.Show();
}
private void InitializeUnity(string args)
{
/* other generated code */
AdManager.CalledAds += AdManager_CalledAds;
}
And this is getting me error: “AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at AppName.App.AdManager_CalledAds(Object sender, EventArgs e)
at AdManager.ShowInterstitial()”
I’ve also tried invoking the AdManager.CalledAds += AdManager_CalledAds; on the app thread within the InitializeUnity method, but it didn’t help.
AppCallbacks.Instance.InvokeOnAppThread(() =>
{
AdManager.CalledAds += AdManager_CalledAds;
}, false);
Building for WSA Phone 8.1, .NET, Win 8.1 64 bit, testing on Lumia 640.