From f3452f32fba45b1f317e4a6a1906d16068ce3bdf Mon Sep 17 00:00:00 2001 From: Sam Moore Date: Sun, 5 Oct 2014 14:32:12 +0800 Subject: [PATCH] Don't sigfpe as much --- .gitignore | 1 + src/Makefile | 3 ++- src/debugscript.cpp | 6 +++--- src/main.cpp | 1 + src/path.h | 2 +- src/real.h | 8 ++++++++ src/screen.cpp | 4 +++- src/shaderprogram.cpp | 2 +- src/view.cpp | 24 ++++++++++++------------ src/view.h | 2 +- 10 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 025bbce..7903839 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ tools/* !src/tests/*.cpp !src/tests/*.h src/*.dll +*.exe diff --git a/src/Makefile b/src/Makefile index c64bebd..04e52fe 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ QT_LIB := -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread LIB_x86_64 = ../contrib/lib/libSDL2-2.0.so.0 -lGL -lgmp LIB_i386 = ../contrib/lib32/libSDL2-2.0.so.0 -lGL -lgmp LIB_i686 = $(LIB_i386) -LIB_win32 = -mwindows -lmingw32 -L../contrib/win32/lib/ -lSDL2main -lSDL2 -lgmp -static-libgcc -static-libstdc++ +LIB_win32 = -mwindows -lmingw32 -L../contrib/win32/lib/ -lSDL2main -lSDL2 -lgmp -static-libgcc -lopengl32 -static-libstdc++ MAINRPATH_x86_64 = -Wl,-rpath,'$$ORIGIN/../contrib/lib' MAINRPATH_i386 = -Wl,-rpath,'$$ORIGIN/../contrib/lib32' @@ -28,6 +28,7 @@ MAINRPATH_win32 = -Wl,-rpath,'$$ORIGIN/../contrib/win32/lib' TESTRPATH_x86_64 = -Wl,-rpath,'$$ORIGIN/../../contrib/lib' TESTRPATH_i386 = -Wl,-rpath,'$$ORIGIN/../../contrib/lib32' TESTRPATH_i686 = $(TESTRPATH_i386) +TESTRPATH_win32 = -Wl,-rpath,'$$ORIGIN/../../contrib/win32/lib' OBJPATHS = $(OBJ:%=../obj/%) DEPS := $(OBJPATHS:%.o=%.d) CFLAGS_x86_64 := -I../contrib/include/SDL2 -I`pwd` diff --git a/src/debugscript.cpp b/src/debugscript.cpp index 9fd95a6..d7ccad3 100644 --- a/src/debugscript.cpp +++ b/src/debugscript.cpp @@ -242,12 +242,12 @@ void DebugScript::PrintPerformance(View * view, Screen * scr) // object_count clock delta_clock x Log10(x) y Log10(y) w Log10(w) Size(w) #ifdef QUADTREE_DISABLED printf("%d\t%llu\t%llu\t%s\t%f\t%s\t%f\t%s\t%f\t%u\n", - now.object_count, (uint64_t)now.clock, - (uint64_t)(now.clock - m_perf_last.clock), + now.object_count, (long long unsigned)now.clock, + (long long unsigned)(now.clock - m_perf_last.clock), Str(now.view_bounds.x).c_str(), Log10(Abs(now.view_bounds.x)), Str(now.view_bounds.y).c_str(), Log10(Abs(now.view_bounds.y)), Str(now.view_bounds.w).c_str(), Log10(now.view_bounds.w), - Size(now.view_bounds.w)); + (unsigned)Size(now.view_bounds.w)); #endif m_perf_last = now; } diff --git a/src/main.cpp b/src/main.cpp index 051f7ce..67e2076 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ void sigfpe_handler(int sig) int main(int argc, char ** argv) { + //Debug("Main!"); signal(SIGFPE, sigfpe_handler); #if REALTYPE == REAL_IRRAM iRRAM_initialize(argc,argv); diff --git a/src/path.h b/src/path.h index fffbeba..06aff7a 100644 --- a/src/path.h +++ b/src/path.h @@ -16,7 +16,7 @@ namespace IPDF { #ifdef TRANSFORM_BEZIERS_TO_PATH - typedef ParanoidNumber PReal; + typedef Gmprat PReal; #else typedef Real PReal; #endif diff --git a/src/real.h b/src/real.h index 42bc5c0..e72709b 100644 --- a/src/real.h +++ b/src/real.h @@ -3,6 +3,7 @@ #include "common.h" #include +#include #define REAL_SINGLE 0 @@ -139,6 +140,13 @@ namespace IPDF inline double Log10(double a) {return log(a)/log(10.0);} inline size_t Size(double a) {return sizeof(a);} inline size_t Size(float a) {return sizeof(a);} + + // Don't cause an exception + inline float ClampFloat(double d) + { + float f = (fabs(d) < FLT_MAX) ? ((fabs(d) > FLT_MIN) ? (float)d : FLT_MIN) : FLT_MAX; + return copysign(f, d); + } inline int64_t Int64(double a) { diff --git a/src/screen.cpp b/src/screen.cpp index 0df64a2..5c11fe1 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -8,6 +8,8 @@ #include "bufferbuilder.h" #include "shaderprogram.h" + + #define BASICTEX_VERT "shaders/basictex_vert.glsl" #define BASICTEX_FRAG "shaders/basictex_frag.glsl" @@ -70,9 +72,9 @@ Screen::Screen(bool visible) m_frame_begin_time = SDL_GetPerformanceCounter(); m_last_frame_time = 0; m_last_frame_gpu_timer = 0; + glGenQueries(1, &m_frame_gpu_timer); glBeginQuery(GL_TIME_ELAPSED, m_frame_gpu_timer); - #ifndef __MINGW32__ glDebugMessageCallback(opengl_debug_callback, 0); #endif diff --git a/src/shaderprogram.cpp b/src/shaderprogram.cpp index 68a4767..c72ad48 100644 --- a/src/shaderprogram.cpp +++ b/src/shaderprogram.cpp @@ -104,7 +104,7 @@ char * ShaderProgram::GetShaderSource(const char * src_file) const bool ShaderProgram::AttachShader(const char * src_file, GLenum type) { GLuint shader_obj = glCreateShader(type); - glObjectLabel(GL_SHADER, shader_obj, -1, src_file); + //glObjectLabel(GL_SHADER, shader_obj, -1, src_file); char * src = GetShaderSource(src_file); if (src == NULL) { diff --git a/src/view.cpp b/src/view.cpp index 5acd860..1d99f2c 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -542,10 +542,10 @@ void View::UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj) obj_bounds = TransformToViewCoords(m_document.m_objects.bounds[id]); } GPUObjBounds gpu_bounds = { - (float)Float(obj_bounds.x), - (float)Float(obj_bounds.y), - (float)Float(obj_bounds.x + obj_bounds.w), - (float)Float(obj_bounds.y + obj_bounds.h) + Float(obj_bounds.x), + Float(obj_bounds.y), + Float(obj_bounds.x + obj_bounds.w), + Float(obj_bounds.y + obj_bounds.h) }; obj_bounds_builder.Add(gpu_bounds); @@ -572,19 +572,19 @@ void View::UpdateObjBoundsVBO(unsigned first_obj, unsigned last_obj) if (!m_use_gpu_transform) obj_bounds = TransformToViewCoords(obj_bounds); GPUObjBounds gpu_bounds = { - Float(obj_bounds.x), - Float(obj_bounds.y), - Float(obj_bounds.x + obj_bounds.w), - Float(obj_bounds.y + obj_bounds.h) + ClampFloat(obj_bounds.x), + ClampFloat(obj_bounds.y), + ClampFloat(obj_bounds.x + obj_bounds.w), + ClampFloat(obj_bounds.y + obj_bounds.h) }; obj_bounds_builder.Add(gpu_bounds); //Debug("Path %d %s -> %s via %s", id, m_document.m_objects.bounds[id].Str().c_str(), obj_bounds.Str().c_str(), pbounds.Str().c_str()); } GPUObjBounds p_gpu_bounds = { - Float(pbounds.x), - Float(pbounds.y), - Float(pbounds.x + pbounds.w), - Float(pbounds.y + pbounds.h) + ClampFloat(pbounds.x), + ClampFloat(pbounds.y), + ClampFloat(pbounds.x + pbounds.w), + ClampFloat(pbounds.y + pbounds.h) }; obj_bounds_builder.Add(p_gpu_bounds); } diff --git a/src/view.h b/src/view.h index 0359565..4bcff89 100644 --- a/src/view.h +++ b/src/view.h @@ -20,7 +20,7 @@ namespace IPDF { #ifdef TRANSFORM_BEZIERS_TO_PATH - typedef ParanoidNumber VReal; + typedef Gmprat VReal; #else typedef Real VReal; #endif -- 2.20.1