Bug 53975 - Xamarin OpenGL GLSurfaceView constructor throws null reference exception
Summary: Xamarin OpenGL GLSurfaceView constructor throws null reference exception
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.3.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2017-03-25 16:46 UTC by talhazengin61
Modified: 2017-03-27 12:21 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description talhazengin61 2017-03-25 16:46:15 UTC
I am trying to implement android LiveWallpaper with Xamarin opengl. But when i activate LiveWallpaper, GLSurfaceView throws null reference exception in constructor.

Error line:
base(context) when calling the base constructor of GLSurfaceView.

Error detail:
Java.Lang.NullPointerException: Attempt to invoke interface method 'void android.view.SurfaceHolder.addCallback(android.view.SurfaceHolder$Callback)' on a null object reference

Here is the code:

[Service(Label = "@string/ApplicationName", Permission = "android.permission.BIND_WALLPAPER")]
[IntentFilter(new[] { "android.service.wallpaper.WallpaperService" })]
[MetaData("android.service.wallpaper", Resource = "@layout/MyLiveWallpaper")]
public class OpenGLWallpaperService : WallpaperService
{
    public override Engine OnCreateEngine()
    {
        return new OpenGLWallpaperEngine(this);
    }

    public class OpenGLWallpaperEngine : Engine
    {
        private readonly OpenGLWallpaperService _serviceInstance;

        public OpenGLWallpaperView GLWallpaperView { get; set; }

        public OpenGLWallpaperEngine(OpenGLWallpaperService serviceInstance)
            : base(serviceInstance)
        {
            _serviceInstance = serviceInstance;
        }

        public override void OnCreate(ISurfaceHolder surfaceHolder)
        {
            base.OnCreate(surfaceHolder);
            GLWallpaperView = new OpenGLWallpaperView(this, _serviceInstance, surfaceHolder);
        }
    }
}

public class OpenGLWallpaperView : GLSurfaceView
{
    private readonly OpenGLWallpaperService.OpenGLWallpaperEngine _engineInstance;

    public override ISurfaceHolder Holder { get; }

    public OpenGLWallpaperView(OpenGLWallpaperService.OpenGLWallpaperEngine engineInstance, 
        Context context, ISurfaceHolder surfaceHolder) 
        : base(context)
    {
        _engineInstance = engineInstance;
        Holder = surfaceHolder;
    }
}
Comment 1 talhazengin61 2017-03-26 13:12:06 UTC
I was doing wrong with override to Holder. Holder should't be overridden.

Cancel this line and related things:
public override ISurfaceHolder Holder { get; }

This is not a bug.