Skip to content
This repository
Browse code

Fixes a bug in the TEXfile class that caused a NullpointerException w…

…hen opening Tex-textures.
  • Loading branch information...
commit 1112d49543d565c47972cbaee75fb384ebbf1520 1 parent 5e1a202
Daniel Senff authored
2  DDSUtils/src/model/AbstractTextureImage.java
@@ -161,7 +161,7 @@ public void write() throws IOException {
161 161
 	 */
162 162
 	@Override
163 163
 	public boolean isCompressed() {
164  
-		return DDSUtil.isDXTCompressed(pixelformat);
  164
+		return PixelFormats.isDXTCompressed(pixelformat);
165 165
 	}
166 166
 	
167 167
 	/**
25  DDSUtils/src/model/MipMaps.java
@@ -57,13 +57,13 @@ public MipMaps(final int numMipMaps) {
57 57
 	 * @param topmost 
58 58
 	 */
59 59
 	public void generateMipMaps(BufferedImage topmost) {
60  
-		this.mipmaps.add(topmost);
  60
+		getMipMaps().add(topmost);
61 61
 		
62 62
 		if(!DDSFile.isPowerOfTwo(topmost.getWidth()) 
63 63
 				&& !DDSFile.isPowerOfTwo(topmost.getHeight())) 
64 64
 			throw new NonCubicDimensionException();
65 65
 		
66  
-		this.mipmaps = generateMipMapArray(this.mipmaps);	
  66
+		this.mipmaps = generateMipMapArray(getMipMaps());	
67 67
 	}
68 68
 
69 69
 	private Vector<BufferedImage> generateMipMapArray(Vector<BufferedImage> mipMapsVector) {
@@ -122,23 +122,30 @@ public int getWidth() {
122 122
 	 * @return
123 123
 	 */
124 124
 	public BufferedImage getMipMap(final int index) {
125  
-		return this.mipmaps.get(index);
  125
+		return getMipMaps().get(index);
126 126
 	}
127 127
 	
128 128
 	/**
129 129
 	 * Set the given {@link BufferedImage} as MipMap in the index.
130  
-	 * @param mipmap
  130
+	 * @param mipmapIndex
131 131
 	 * @param image
132 132
 	 */
133  
-	public void setMipMap(int mipmap, BufferedImage image) {
134  
-		this.mipmaps.set(mipmap, image);
  133
+	public void setMipMap(int mipmapIndex, BufferedImage image) {
  134
+		if(getMipMaps().size() == mipmapIndex)
  135
+			getMipMaps().add(mipmapIndex, image);
  136
+		else
  137
+			getMipMaps().set(mipmapIndex, image);
  138
+	}
  139
+
  140
+	private Vector<BufferedImage> getMipMaps() {
  141
+		return this.mipmaps;
135 142
 	}
136 143
 	
137 144
 	/**
138 145
 	 * @param image
139 146
 	 */
140 147
 	public void addMipMap(final BufferedImage image) {
141  
-		this.mipmaps.add(image);
  148
+		getMipMaps().add(image);
142 149
 	}
143 150
 	
144 151
 	/**
@@ -163,7 +170,7 @@ public void addMipMap(final BufferedImage image) {
163 170
 	 * @return
164 171
 	 */
165 172
 	public Vector<BufferedImage> getAllMipMaps() {
166  
-		return this.mipmaps;
  173
+		return getMipMaps();
167 174
 	}
168 175
 	
169 176
 	/**
@@ -171,7 +178,7 @@ public void addMipMap(final BufferedImage image) {
171 178
 	 * @return
172 179
 	 */
173 180
 	public BufferedImage[] getAllMipMapsArray() {
174  
-		return (BufferedImage[]) this.mipmaps.toArray();
  181
+		return (BufferedImage[]) getMipMaps().toArray();
175 182
 	}
176 183
 
177 184
 	/* (non-Javadoc)
1  DDSUtils/src/model/TEXFile.java
@@ -58,6 +58,7 @@ protected void init(final TEXImage image) {
58 58
 		this.depth 			= image.getDepth();
59 59
 		this.pixelformat 	= image.getPixelFormat();
60 60
 		this.numMipMaps 	= image.getNumMipMaps();
  61
+		this.mipMaps 		= new MipMaps(this.numMipMaps);
61 62
 		this.hasMipMaps		= (image.getNumMipMaps() > 1); // there is always at least the topmost MipMap
62 63
 	}
63 64
 	

0 notes on commit 1112d49

Please sign in to comment.
Something went wrong with that request. Please try again.