Roi Atalla avatar Roi Atalla committed a1cc501

Added null-checks in Mesh.

Comments (0)

Files changed (1)

src/main/java/com/ra4king/opengl/util/Mesh.java

 					case XmlPullParser.START_TAG:
 						switch(xml.getName()) {
 							case "attribute": {
-								int index = Integer.parseInt(xml.getAttributeValue(null, "index"));
+								String index = xml.getAttributeValue(null, "index");
 								String type = xml.getAttributeValue(null, "type");
-								int size = Integer.parseInt(xml.getAttributeValue(null, "size"));
+								String size = xml.getAttributeValue(null, "size");
 								
-								Attribute attrib = new Attribute(index,type,size);
+								if(index == null)
+									throw new IllegalArgumentException("<attribute> missing 'index'");
+								if(type == null)
+									throw new IllegalArgumentException("<attribute> missing 'type'");
+								if(size == null)
+									throw new IllegalArgumentException("<attribute> missing 'size'");
+								
+								Attribute attrib = new Attribute(Integer.parseInt(index),type,Integer.parseInt(size));
 								attributes.add(attrib);
 								
 								xml.next();
 								String primitive = xml.getAttributeValue(null, "cmd");
 								String type = xml.getAttributeValue(null, "type");
 								
+								if(primitive == null)
+									throw new IllegalArgumentException("<indices> missing 'cmd'");
+								if(type == null)
+									throw new IllegalArgumentException("<indices> missing 'type'");
+								
 								RenderCmd cmd = new RenderCmd(primitive,type);
 								renderCommands.add(cmd);
 								
 								if(vaos == null)
 									vaos = new ArrayList<VAO>();
 								
-								VAO vao = new VAO(xml.getAttributeValue(null, "name"));
+								String name = xml.getAttributeValue(null, "name");
+								
+								if(name == null)
+									throw new IllegalArgumentException("<vao> missing 'name'");
+								
+								VAO vao = new VAO(name);
 								vaos.add(vao);
 								
 								while(xml.nextTag() == XmlPullParser.START_TAG) {
 									xml.require(XmlPullParser.START_TAG, null, "source");
-									vao.sources.add(Integer.parseInt(xml.getAttributeValue(null, "attrib")));
+									
+									String attrib = xml.getAttributeValue(null, "attrib");
+									
+									if(attrib == null)
+										throw new IllegalArgumentException("<source> missing 'attrib'");
+									
+									vao.sources.add(Integer.parseInt(attrib));
 									xml.nextTag();
 									xml.require(XmlPullParser.END_TAG, null, "source");
 								}
 							}
 							case "arrays": {
 								String primitive = xml.getAttributeValue(null, "cmd");
-								int start = Integer.parseInt(xml.getAttributeValue(null, "start"));
-								int count = Integer.parseInt(xml.getAttributeValue(null, "count"));
+								String start = xml.getAttributeValue(null, "start");
+								String count = xml.getAttributeValue(null, "count");
 								
-								RenderCmd cmd = new RenderCmd(primitive,start,count);
+								if(primitive == null)
+									throw new IllegalArgumentException("<arrays> missing 'cmd'");
+								if(start == null)
+									throw new IllegalArgumentException("<arrays> missing 'start'");
+								if(count == null)
+									throw new IllegalArgumentException("<arrays> missing 'count'");
+								
+								RenderCmd cmd = new RenderCmd(primitive,Integer.parseInt(start),Integer.parseInt(count));
 								renderCommands.add(cmd);
 								
 								xml.next();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.