three_cpp icon indicating copy to clipboard operation
three_cpp copied to clipboard

Compiling on GCC, 64 bit Ubuntu

Open stuaxo opened this issue 11 years ago • 2 comments

I got the following error compiling

 stu  beezlebub  ~  projects  external  three_cpp  build  master  $ make
Scanning dependencies of target three
[  4%] Building CXX object CMakeFiles/three.dir/three/impl/src.cpp.o
[  9%] Building CXX object CMakeFiles/three.dir/three/impl/src_extras.cpp.o
In file included from /home/stu/projects/external/three_cpp/./three/impl/src_extras.hpp:12:0,
                 from /home/stu/projects/external/three_cpp/three/impl/src_extras.cpp:2:
/home/stu/projects/external/three_cpp/./three/extras/utils/impl/font.ipp: In function ‘std::vector<unsigned char> three::detail::load(const string&)’:
/home/stu/projects/external/three_cpp/./three/extras/utils/impl/font.ipp:29:38: error: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Werror=unused-result]
   fread( buffer.data(), 1, size, fp );
                                      ^
compilation terminated due to -Wfatal-errors.
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/three.dir/three/impl/src_extras.cpp.o] Error 1
make[1]: *** [CMakeFiles/three.dir/all] Error 2
make: *** [all] Error 2

This patch fixes it, but it's probably a workaround - either the warning should be disabled, or probably add some code that does something better in the error state (not sure what threejs does if you try and load a font thats not available).

diff --git a/three/extras/utils/impl/font.ipp b/three/extras/utils/impl/font.ipp
index 3626724..9683e79 100644
--- a/three/extras/utils/impl/font.ipp
+++ b/three/extras/utils/impl/font.ipp
@@ -26,7 +26,10 @@ inline std::vector<unsigned char> load( const std::string& file ) {
   fseek( fp, 0, SEEK_SET );

   std::vector<unsigned char> buffer( size );
-  fread( buffer.data(), 1, size, fp );
+  int sizeRead = fread( buffer.data(), 1, size, fp );
+  if (sizeRead != size) {
+      printf("Error loading font");
+  }
   fclose( fp );
   return buffer;
 }
@@ -244,4 +247,4 @@ const Texture::Ptr& Font::texture() const {

 } // namespace three

-#endif // THREE_FONT2_IPP
\ No newline at end of file
+#endif // THREE_FONT2_IPP

stuaxo avatar Nov 17 '14 14:11 stuaxo

Thanks for the report @stuaxo, might I ask which compiler (including its version) you're using?

jdduke avatar Nov 24 '14 00:11 jdduke

Hi, It's GCC, 4.8.2

$ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

stuaxo avatar Nov 24 '14 18:11 stuaxo