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

Suggestion to Resolve Small Warning in loadModel() #8

Open
apotvin96 opened this issue Aug 31, 2015 · 0 comments
Open

Suggestion to Resolve Small Warning in loadModel() #8

apotvin96 opened this issue Aug 31, 2015 · 0 comments

Comments

@apotvin96
Copy link

loadModel will currently show a warning in eclipse and other java IDE that the reader of type BufferedReader has not been closed. This is due to a try/catch/finally/needed. I have been watching these to transfer from c++ opengl work to java and noticed this issue and just wanted to give a heads up. I edited my personal copy of the code here...

public static Model loadModel(File f) throws IOException {
    BufferedReader reader = null;
    Model m = null;
    try{
        reader = new BufferedReader(new FileReader(f));
        m = new Model();
        String line;
        while ((line = reader.readLine()) != null) {
            String prefix = line.split(" ")[0];
            if (prefix.equals("#")) {
                continue;
            } else if (prefix.equals("v")) {
                m.getVertices().add(parseVertex(line));
            } else if (prefix.equals("vn")) {
                m.getNormals().add(parseNormal(line));
            } else if (prefix.equals("f")) {
                m.getFaces().add(parseFace(m.hasNormals(), line));
            } else {
                throw new RuntimeException("OBJ file contains line which cannot be parsed correctly: " + line);
            }
        }
    }catch (Exception e){
        System.out.println(e.getMessage());
    }finally{
        reader.close();
    }

    return m;
}
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

1 participant