AdMob interstitial crashes with NullReferenceException in GoogleAds.DLL - windows-phone-8

I am trying to integrate an interstitial AdMob ad into a Windows Phone 8 MonoGame. It is the newest version of MonoGame (3.2) and the newest version of the AdMob SDK for Windows Phone 8 (6.5.13). Ideally I would like to be able to preload the ad and show it when the player dies.
This first example works, but it calls ShowAd directly in the event handler when the ad was received.
public void LoadAndShowAd()
{
interstitial = new InterstitialAd("xxx");
interstitial.ReceivedAd += OnAdReceived;
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitial.LoadAd(adRequest);
}
private void OnAdReceived(object sender, AdEventArgs e)
{
interstitial.ShowAd();
}
This slightly modified example does not work. The ad is received and is ready, but the call to ShowAd crashes within the GoogleAds.DLL with a NullReferenceException. As you can see the only difference is that ShowLoadedAd is called at a later point in time when the ad is ready.
public void LoadAd()
{
interstitial = new InterstitialAd("xxx");
interstitial.ReceivedAd += OnAdReceived;
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitial.LoadAd(adRequest);
}
public void ShowLoadedAd()
{
if (isReady)
interstitial.ShowAd();
}
private void OnAdReceived(object sender, AdEventArgs e)
{
isReady = true;
}
The "interstitial" object itself is not null, the exception happens within the GoogleAds dll as shown in the stack trace below. The exception itself sadly does not give away much:
System.NullReferenceException was unhandled by user code HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=GoogleAds
StackTrace:
at A.c81d6e02e9732689b8a214cc526c72649.c8b6f578dd247fa29b178e585ca8da582()
at A.c81d6e02e9732689b8a214cc526c72649.ce00282f6ceb6d2b777527815c84e2081()
at GoogleAds.InterstitialAd.ShowAd()
at GameName10.GamePage.<Test2>b__1()
InnerException:
The Google Ads example for Windows Phone 8 and interstitial ads actually uses the second approach which causes the exception in my monogame project. So I assumed it could be an issue with these calls being made from the game loop of monogame being in a different thread. I wrapped all the calls to these functions in Dispatcher.BeginInvoke calls to make sure they are called on the UI thread. However this does not change anything, the first example works regardless if it is wrapped in BeginInvoke or not and the second one does not.
Any input in how to solve this issue or integrate an interstitial AdMob ad into MonoGame successfully is appreciated.
Thanks

Related

Can't set config.forceExit in LibGDX (Lwjgl3)

Here is my Desktop Launcher code:
public class DesktopLauncher {
public static void main (String[] arg) {
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setForegroundFPS(60);
config.setTitle("Game10");
config.setWindowedMode(1240, 760);
config.forceExit = false; // ERROR!!!
new Lwjgl3Application(new GdxGame10(), config);
}
}
In new LWJGL3 config.forceExit not working. I can't find any solution so far. Any help is appreciated.
There is no forceExit in config. So presumably you have a master application that runs a child libGDX component and when you end that child component you find that the entire application shuts down, when you want the master application to continue. I guess you are on desktop because Android would be OK. So you must want to avoid a full System.exit
i.e.
Gdx.app.exit()
shuts down everything.
So when you instantiate a libGDX application you instantiate based on the application type, so for me, I use the same as you
final Lwjgl3Application application = new Lwjgl3Application(Services.GAME_CONTROLLER,config);
and the implementation for exit is
#Override
public void exit () {
running = false;
}
This finished the while loop that drives the application i.e. kills the main thread. If you have -other threads- running in the background they keep going.
If on the other hand you were instantiating LwglAWTCanvas then your shutdown would be this.
#Override
public void exit () {
postRunnable(new Runnable() {
#Override
public void run () {
stop();
System.exit(-1);
}
});
}
which would shut down the entire application. Anyway so forceExit being -false- was to stop a full system exit killing all your threads. The forceExit was to "force" the other threads to finish. It doesn't do that anymore so the fact it is now missing should not matter, your background threads should keep going.
In other words, config.forceExit = false; is now the default behaviour for your application type so you don't need it.

GPS running in background when Here Drive+ is running

i have a problem running my wp (8.0) app properly in the background when HERE Drive+ is running in the foreground. my app is a location based app.
i've setup a little demo project to reproduce and isolate and simplify the problem.
I have a GeoLocator, which is checking and displaying the current location in the PositionChanged event to a label, when in foreground. when running in background, it displays a toast every 5 seconds (to show me, that the PositionChanged event is still triggered).
pretty forward stuff, that works.
public MainPage()
{
InitializeComponent();
DataContext = this;
App.LocationWatcher.ReportInterval = 5000;
App.LocationWatcher.DesiredAccuracy = PositionAccuracy.High;
App.LocationWatcher.PositionChanged += LocationWatcherOnPositionChanged;
App.LocationWatcher.StatusChanged += LocationWatcherOnStatusChanged;
}
private void LocationWatcherOnStatusChanged(Geolocator sender, StatusChangedEventArgs args)
{
DisplayToast("Status:", args.Status.ToString());
}
private void LocationWatcherOnPositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
if (!App.IsRunningInBackground)
{
Dispatcher.BeginInvoke(() => {
this.tbkLastUpdatedValue.Text = DateTime.Now.Ticks.ToString();
this.tbkLatitudeValue.Text = args.Position.Coordinate.Latitude.ToString();
this.tbkLongitudeValue.Text = args.Position.Coordinate.Longitude.ToString();
});
}
else
{
DisplayToast("Location:", args.Position.Coordinate.Latitude.ToString());
}
}
So, now the problem: When my app runs in background, it displays it's toasts, when i run any other app (including the normal map, which actually uses gps), but when i run HERE Drive+, my PositionChanged and my StatusChanged events dont get triggered anymore.
there is an app on the marketplace that is capable to run in background when here drive+ is running in foreground, as stated in the marketplace comments (in german only)
any ideas how to solve this or what may cause that problem?
The Windows SDK is no longer. An alternative could be to use the HERE Maps API for Javascript, which supports vector map data rendering.

White screen appears after dismissing Admob interstitial ad

I am having an issue with the interstitial ads where on dismissing the interstitial ads, a white screen appears for 2-3 seconds, which is non responsive, and only after 2-3 seconds, it disappears and the app becomes visible again.
Platform: WP8
SDK version: GoogleMobileAdsSdkWindowsPhone8-6.5.13
Code snippet is below (I have placed only the required stuff, apologies in advance if it proves to be difficult to work with)
/*
C# implementation of the s3eAdMob extension.
Add win8-specific functionality here.
These functions are called via Shim class from native code.
*/
/*
* NOTE: This file was originally written by the extension builder, but will not
* be overwritten (unless --force is specified) and is intended to be modified.
*/
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using System.Windows.Media;
using System.Windows;
using System.Threading.Tasks;
using GoogleAds;
namespace s3eAdMobManaged
{
public class s3eAdMobManaged
{
private string interstitialAdID = "ca-app-pub-3090050976150818/7861588484";
private InterstitialAd interstitialAd;
public void initAdMob_managed()
{
interstitialAd = new InterstitialAd(interstitialAdID);
interstitialAd.DismissingOverlay += OnInterstitialDismissingOverlay;
AdRequest adRequestInterstitial = new AdRequest();
adRequestInterstitial.ForceTesting = false;
interstitialAd.LoadAd(adRequestInterstitial);
}
public void showAdMobInterstitial_managed()
{
interstitialAd.ShowAd();
}
private void OnInterstitialDismissingOverlay(object sender, AdEventArgs e)
{
loadInterstitialAdAsync();
}
private async void loadInterstitialAdAsync () {
await Task.Run(() => loadInterstitialAd());
}
private void loadInterstitialAd()
{
interstitialAd = new InterstitialAd(interstitialAdID);
interstitialAd.DismissingOverlay += OnInterstitialDismissingOverlay;
AdRequest adRequestInterstitial = new AdRequest();
adRequestInterstitial.ForceTesting = false;
interstitialAd.LoadAd(adRequestInterstitial);
}
}
}
Description of the code:
initAdMob_managed: For initialization. Called by the app on startup. Loads the ad but does not show it.
showAdMobInterstitial_managed: For showing the already loaded ad.
OnInterstitialDismissingOverlay: Callback that gets executed on dismissing the ad. I am using this method to reload the ad data so that it will be available the next time it is to be shown, this task is carried out asynchronously since the data being loaded is not required right away. When need be, showAdMobInterstitial_managed will get called.
Initially, I thought that it could be OnInterstitialDismissingOverlay logic issue. So, I removed this method altogether (removing this method will cause issue in reloading the ad, but the first time execution should be without any issue). Even after the removal, there was no change.
Thanks,
Ashish
I have the same problem, different engine. You appear to be using marmalade?
If you look at the admob interstitial samples for WP8, you see that they have this white version too as soon as you close the ad.
It just doesn't show that long, as the context switch doesn't take so long.
The engine I am currently using also takes a while to switch back from the ad to the game.
I guess you have encountered the same problem?
My tip: test your game in release mode and without a debugger or console attached ... this speeded up the whole process and the white ad now only is visible for like 1 second compared to 4-5 ... maybe that helps.

Trigger a phone call in Windows Phone 8 application

I need to develop an app to make a call from the Windows Phone 8 app using Visual Studio.
But I couldn't find any resources to do it.
When a button is clicked I need to call to a mobile number which is already given.
By clicking that button I must call only to that mobile number.
This is what I coded. When a given button is clicked, I this method is calling...
private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)
{
PhoneCallTask phoneCallTask = new PhoneCallTask();
phoneCallTask.PhoneNumber = "0719957868";
phoneCallTask.DisplayName = "Gage";
phoneCallTask.Show();
}
But I get an unhandled exception.
Unhandled exception.
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
Debugger.Break();
}
}
When you use PhoneCallTask, you have to specify a new Capability of your app in WMAppManifest.xaml: ID_CAP_PHONEDIALER
source
This is how you should do it:
PhoneCallTask phoneCallTask = new PhoneCallTask();
phoneCallTask.PhoneNumber = "2065550123";
phoneCallTask.DisplayName = "Gage";
phoneCallTask.Show();
Remember that the call is not automatically started but it prompts the user to confirm that action.
Here is how to initiate a call on windows phone
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394025(v=vs.105).aspx
Ok for future reference i must add this.
If you get an Unauthorized Access Exception then you need to enable ID_CAP_PHONEDAILER from the Capabilities section in the WMAppManifest.xml file.
See here

ReadingChanged never called for Accelerometer on WP8

I'm trying to use the C++ Accelerometer interface in the Windows::Devices::Sensors namespace on the Windows Phone 8. The code is very similar to a C# project I have that works, but I can't get the C++ event to fire like I can with my C# code.
My C++ code is a C# project with a C++ component, the C++ component just opens up the Accelerometer device for reading, and then tries to setup an event to fire whenever data is ready:
AccelerometerWrapper::AccelerometerWrapper() {
Accelerometer^ acc = Accelerometer::GetDefault();
accReading = acc->ReadingChanged::add( ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &AccelerometerWrapper::ReadingChanged));
}
void AccelerometerWrapper::ReadingChanged(Accelerometer^ sender, AccelerometerReadingChangedEventArgs^ e) {
...
}
Unfortunately, my ReadingChanged() function is never being called. I've looked around for a Start() method or somesuch but I can't find anything. I'm basing most of my knowledge off of the AccelerometerCPP example, but I can't actually test that as it is a generic WinRT (e.g. Windows 8, not Windows Phone 8) example, and my computer does not have an accelerometer. Everything compiles and runs, the event is just never triggered.
EDIT: I have successfully run a test to verify that I can manually call acc->GetCurrentReading(), so the accelerometer is working, it just seems to be the event that is not getting triggered.
Thank you in advance!
I'm not a C++ expert, but the new Accelerometer sensor works on my machine using C#.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var accelerometer = Accelerometer.GetDefault();
if (accelerometer != null)
{
accelerometer.ReadingChanged += accelerometer_ReadingChanged;
}
}
void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
Debug.WriteLine(args.Reading.AccelerationX + ", " + args.Reading.AccelerationY + "," + args.Reading.AccelerationZ);
}
When we run that code snippet we can see the following expected output:
Just a guess for C++, do you need to cache the Accelerometer instance somewhere instead of letting it go out of scope?