fix possible division by zero in ccdemos/common_ply.h pyrit
authorRadek Brich <radek.brich@devl.cz>
Tue, 18 Dec 2007 12:36:01 +0100
branchpyrit
changeset 41 c1080cb5bd6d
parent 40 929aad02c5f2
child 42 fbdeb3e04543
fix possible division by zero in ccdemos/common_ply.h don't use DEFS variable in makefiles, just add it to CCFLAGS compile float version of libs with -fsingle-precision-constant
ccdemos/Makefile
ccdemos/common_ply.h
config.mk
demos/objreader.py
demos/plyreader.py
src/Makefile
--- a/ccdemos/Makefile	Mon Dec 17 22:03:50 2007 +0100
+++ b/ccdemos/Makefile	Tue Dec 18 12:36:01 2007 +0100
@@ -4,13 +4,18 @@
 
 include $(ROOT)/config.mk
 
+### single precision
+#RTLIBS=libs-float
+#CCFLAGS+=-fsingle-precision-constant
+
+### double precision
 RTLIBS=libs-double
-DEFS+=-DPYRIT_DOUBLE
+CCFLAGS+=-DPYRIT_DOUBLE
 
 
 ### Rules ###
 %.o: %.cc
-	$(CXX) -c -o $@ $(CCFLAGS) $(SDL_CCFLAGS) $< $(DEFS)
+	$(CXX) -c -o $@ $(CCFLAGS) $(SDL_CCFLAGS) $<
 
 %: %.o
 	$(CXX) -o $@ $(ROOT)/bin/$(RTLIBS)/*.o $< image.o $(LDFLAGS) $(SDL_LDFLAGS) -lpng
--- a/ccdemos/common_ply.h	Mon Dec 17 22:03:50 2007 +0100
+++ b/ccdemos/common_ply.h	Tue Dec 18 12:36:01 2007 +0100
@@ -71,11 +71,12 @@
 	}
 
 	for (int i = 0; i < vertex_num; i++)
-	{
-		normals.at(i) /= vertex_face_num.at(i);
-		normals.at(i).normalize();
-		vertices.at(i)->N = normals.at(i);
-	}
+		if (vertex_face_num.at(i))
+		{
+			normals.at(i) /= vertex_face_num.at(i);
+			normals.at(i).normalize();
+			vertices.at(i)->N = normals.at(i);
+		}
 
 	f.close();
 }
--- a/config.mk	Mon Dec 17 22:03:50 2007 +0100
+++ b/config.mk	Tue Dec 18 12:36:01 2007 +0100
@@ -1,5 +1,3 @@
-DEFS=-DPTHREADS
-
 CCFLAGS=-g -Wall -Wno-write-strings -fno-strict-aliasing -I$(ROOT)/include
 LDFLAGS=
 
@@ -10,12 +8,13 @@
 SDL_LDFLAGS=$(shell sdl-config --libs)
 
 ifeq ($(OS), Windows_NT)
+  CCFLAGS+=-DPTHREADS
   LDFLAGS+=-lpthreadGC2
-  PY_CCFLAGS=-I"C:/Program Files/Python25/include"
+  PY_CCFLAGS=-I"C:\Program Files\Python25\include"
   PY_LDFLAGS=-L"C:\Program Files\Python25\libs" -lpython25
   MODULENAME=raytracer.pyd
 else
-  CCFLAGS+=-pthread -fPIC
+  CCFLAGS+=-pthread -DPTHREADS -fPIC
   LDFLAGS+=-pthread
   MODULENAME=raytracermodule.so
 endif
--- a/demos/objreader.py	Mon Dec 17 22:03:50 2007 +0100
+++ b/demos/objreader.py	Tue Dec 18 12:36:01 2007 +0100
@@ -1,3 +1,5 @@
+# Wavefron .obj file loader
+
 from raytracer import Triangle, NormalVertex
 
 def LoadWavefrontObjFile(rt, filename, mat, scale):
--- a/demos/plyreader.py	Mon Dec 17 22:03:50 2007 +0100
+++ b/demos/plyreader.py	Tue Dec 18 12:36:01 2007 +0100
@@ -1,3 +1,5 @@
+# Stanford .ply file loader
+
 from raytracer import Triangle, NormalVertex
 
 def LoadStanfordPlyFile(rt, filename, mat, smooth, scale=(1,1,1), trans=(0,0,0)):
--- a/src/Makefile	Mon Dec 17 22:03:50 2007 +0100
+++ b/src/Makefile	Tue Dec 18 12:36:01 2007 +0100
@@ -14,11 +14,11 @@
 
 libs-float:
 	mkdir -p $(ROOT)/bin/$@
-	$(MAKE) -C $(ROOT)/bin/$@ -f $(ROOT)/src/Makefile libs ROOT="$(ROOT)"
+	$(MAKE) -C $(ROOT)/bin/$@ -f $(ROOT)/src/Makefile libs ROOT="$(ROOT)" CCFLAGS="$(CCFLAGS) -fsingle-precision-constant"
 
 libs-double:
 	mkdir -p $(ROOT)/bin/$@
-	$(MAKE) -C $(ROOT)/bin/$@ -f $(ROOT)/src/Makefile libs ROOT="$(ROOT)" DEFS="$(DEFS) -DPYRIT_DOUBLE"
+	$(MAKE) -C $(ROOT)/bin/$@ -f $(ROOT)/src/Makefile libs ROOT="$(ROOT)" CCFLAGS="$(CCFLAGS) -DPYRIT_DOUBLE"
 
 libs: $(LIBOBJS)
 
@@ -36,7 +36,7 @@
 
 ### Rules ###
 %.o: %.cc
-	$(CXX) -c -o $@ $(DEFS) $(CCFLAGS) $<
+	$(CXX) -c -o $@ $(CCFLAGS) $<
 
 
 ### Dependencies ###
@@ -49,4 +49,4 @@
 raytracer.o: raytracer.cc raytracer.h scene.h vector.h noise.h common.h
 
 raytracermodule.o: raytracermodule.cc $(LIBOBJS)
-	$(CXX) -c -o $@ $(DEFS) $(CCFLAGS) $(PY_CCFLAGS) $<
+	$(CXX) -c -o $@ $(CCFLAGS) $(PY_CCFLAGS) $<