add missing NULL check in RB_dworld_export if fopen fails.
authorCampbell Barton <ideasman42@gmail.com>
Sun, 4 Aug 2013 04:30:14 +0000 (04:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 4 Aug 2013 04:30:14 +0000 (04:30 +0000)
intern/rigidbody/rb_bullet_api.cpp

index 58e355c..5724d19 100644 (file)
@@ -57,6 +57,7 @@ subject to the following restrictions:
  */
 
 #include <stdio.h>
+#include <errno.h>
 
 #include "RBI_api.h"
 
@@ -218,8 +219,13 @@ void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
        world->dynamicsWorld->serialize(serializer);
        
        FILE *file = fopen(filename, "wb");
-       fwrite(serializer->getBufferPointer(), serializer->getCurrentBufferSize(), 1, file);
-       fclose(file);
+       if (file) {
+               fwrite(serializer->getBufferPointer(), serializer->getCurrentBufferSize(), 1, file);
+               fclose(file);
+       }
+       else {
+                fprintf(stderr, "RB_dworld_export: %s\n", strerror(errno));
+       }
 }
 
 /* ********************************** */