Search Unity

Unity WSA ads - AccessViolation when calling event from VS

Discussion in 'Windows' started by Simon_says, Feb 24, 2016.

  1. Simon_says

    Simon_says

    Joined:
    Oct 19, 2013
    Posts:
    141
    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:
    Code (CSharp):
    1. public static event EventHandler CalledAds;
    2.  
    3. // called with UI button
    4. private void ShowInterstitial()
    5. {
    6.     if (CalledAds != null)
    7.         CalledAds(null, null);
    8. }
    and in the VS generated project in App.xaml.cs:
    Code (CSharp):
    1. private InterstitialAd ads;
    2. public App()
    3. {
    4.      this.InitializeComponent();
    5.      appCallbacks = new AppCallbacks();
    6.      ads = new InterstitialAd();
    7.      ads.RequestAd(AdType.Video, appId, adUnitId);
    8. }
    9.  
    10. private void AdManager_CalledAds(object sender, EventArgs e)
    11. {
    12.      if (ads.State == InterstitialAdState.Ready)
    13.           ads.Show();
    14. }
    15.  
    16. private void InitializeUnity(string args)
    17. {
    18.      /* other generated code */
    19.      AdManager.CalledAds += AdManager_CalledAds;
    20. }
    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.

    Code (CSharp):
    1. AppCallbacks.Instance.InvokeOnAppThread(() =>
    2. {
    3.      AdManager.CalledAds += AdManager_CalledAds;
    4. }, false);
    Building for WSA Phone 8.1, .NET, Win 8.1 64 bit, testing on Lumia 640.
     
    Last edited: Feb 24, 2016
  2. Simon_says

    Simon_says

    Joined:
    Oct 19, 2013
    Posts:
    141