Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading textures from resources - easy fix! #31

Open
wernerlaurence opened this issue Nov 21, 2013 · 1 comment
Open

Error loading textures from resources - easy fix! #31

wernerlaurence opened this issue Nov 21, 2013 · 1 comment

Comments

@wernerlaurence
Copy link

Hello,

Firstly, thank you to everyone involved in this project - amazing work!

I had a problem getting the lesson 08 example working, kept getting an NullPointerException on loading the resource:

(...)
public void loadGLTexture(GL10 gl, Context context) {
//Get the texture from the Android resource directory
InputStream is = context.getResources().openRawResource(l.werner.livewallpaper.hypnoclockgl.R.drawable.nehe_android);
Bitmap bitmap = null;
try {
//BitmapFactory is an Android graphics utility for images
bitmap = BitmapFactory.decodeStream(is);

        } finally {
                //Always clear and close
                try {
                        is.close();
                        is = null;
                } catch (IOException e) {
                }
        }

(...)

I found that the easiest way to fix this nullpointerexception is to modify the constructor in MyWallpaperService.MyEngine to include

renderer.setContext(getApplicationContext());

Full method:
public MyEngine()
{
super();
// handle prefs, other initialization
renderer = new MyRenderer();
setRenderer(renderer);
setRenderMode(RENDERMODE_CONTINUOUSLY);
renderer.setContext(getApplicationContext());
}

Anyways, hope this helps someone!

Thanks again to Mark F Guerra and Robert Green!

LW

@markfguerra
Copy link
Owner

Thanks! I'll try this out next time I'm messing around with this project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants