Merge pull request #408 from marco-langer/feature/ostream_error_handling

Added error checking to ostream writing
diff --git a/tests/tester.cc b/tests/tester.cc
index 1eeeadd..dc653ff 100644
--- a/tests/tester.cc
+++ b/tests/tester.cc
@@ -504,7 +504,8 @@
   std::stringstream os;
 
   tinygltf::TinyGLTF ctx;
-  ctx.WriteGltfSceneToStream(&m, os, false, false);
+  bool ret = ctx.WriteGltfSceneToStream(&m, os, false, false);
+  REQUIRE(true == ret);
 
   // use nlohmann json
   nlohmann::json j = nlohmann::json::parse(os.str());
@@ -532,7 +533,8 @@
 
   std::stringstream os;
 
-  ctx.WriteGltfSceneToStream(&model, os, false, false);
+  ret = ctx.WriteGltfSceneToStream(&model, os, false, false);
+  REQUIRE(true == ret);
 
   // use nlohmann json
   nlohmann::json j = nlohmann::json::parse(os.str());
@@ -634,8 +636,9 @@
   std::stringstream os;
 
   tinygltf::TinyGLTF ctx;
-  ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
+  bool ret = ctx.WriteGltfSceneToStream(const_cast<const tinygltf::Model *>(&m), os, false,
                              false);
+  REQUIRE(true == ret);
   REQUIRE(m.images[0].uri == i.uri);
 
   // use nlohmann json
diff --git a/tiny_gltf.h b/tiny_gltf.h
index c935b89..e8f6f60 100644
--- a/tiny_gltf.h
+++ b/tiny_gltf.h
@@ -7780,7 +7780,7 @@
 
 static bool WriteGltfStream(std::ostream &stream, const std::string &content) {
   stream << content << std::endl;
-  return true;
+  return stream.good();
 }
 
 static bool WriteGltfFile(const std::string &output,
@@ -7863,8 +7863,8 @@
     }
   }
 
-  // TODO: Check error on stream.write
-  return true;
+  stream.flush();
+  return stream.good();
 }
 
 static bool WriteBinaryGltfFile(const std::string &output,