We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › nullpointerexeption in program to load terrain
Page Index Toggle Pages: 1
nullpointerexeption in program to load terrain (Read 591 times)
nullpointerexeption in program to load terrain
May 11th, 2009, 5:20pm
 
The program reads data from a heightmap and colormap to make terrain for a game I'm making.

I get the exception at the starred line.

Code:
/**Unnamed Game by Jonah
*/

import damkjer.ocd.*;

PImage[][] levels;
//Player player;
Terrain test;
Camera standard;

void setup() {
size(700,700,P3D);
levels=new PImage[1][3];
levels[0][0]=loadImage("testHeight.jpg");
levels[0][1]=loadImage("testColor.jpg");
levels[0][2]=loadImage("testCube.jpg");
standard=new Camera(this,50);
test=new Terrain(levels[0][0],levels[0][1],levels[0][2]);
noStroke();
}

void draw() {
background(0);
lights();
standard.feed();
test.disp();
}

class Terrain {
int[][] heightMap;
color[][] colorMap;
boolean[][] squareMap;
Terrain(PImage heightM,PImage colorM, PImage squaresM) {
heightMap=new int[600][600];
colorMap=new color[600][600];
squareMap=new boolean[600][600];
PGraphics maps=createGraphics(600,600,P3D);
maps.beginDraw();
image(heightM,0,0);
maps.loadPixels();
for(int q=0;q<600;q++) {
for(int w=0;w<600;w++) {
***** heightMap[q][w]=255-int(blue(pixels[600*q+w]));
}
}
image(colorM,0,0);
maps.loadPixels();
for(int q=0;q<600;q++) {
for(int w=0;w<600;w++) {
colorMap[q][w]=pixels[600*q+w];
}
}
image(squaresM,0,0);
maps.loadPixels();
for(int q=0;q<600;q++) {
for(int w=0;w<600;w++) {
if (blue(pixels[600*q+w])==0) {
squareMap[q][w]=true;
}
else {
squareMap[q][w]=false;
}
}
}
maps.endDraw();
}

void disp() {
for(int z=0;z<600;z++) {
for(int x=0;x<600;x++) {
fill(colorMap[z][x]);
translate(x,heightMap[z][x]/2,z);
box(1,heightMap[z][x],1);
translate(0,heightMap[z][x]/2,0);
if(!squareMap[z][x]) {
sphere(1);
}
translate(-1*x,-1*heightMap[z][x],-1*z);
}
}
}
}

Re: nullpointerexeption in program to load terrain
Reply #1 - May 11th, 2009, 10:19pm
 
You perform maps.loadPixels() for the image, but just use 'pixels[]' on that line.

Since it hasn't made it through setup(), the sketch's pixels array doesn't point to anything yet.
Page Index Toggle Pages: 1