From 192aa7604ee8e40f1e32334584c2f7f6b073a102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 17 Dec 2013 23:01:36 +0100 Subject: [PATCH] Fixed several minor memory race bugs --- Makefile | 2 +- src/render/software/CloudBasicLayerRenderer.cpp | 11 +++++++---- src/render/software/CloudsRenderer.cpp | 4 +++- src/render/software/TerrainRasterizer.cpp | 2 +- src/render/software/WaterRasterizer.cpp | 2 +- src/system/System.cpp | 7 +++++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 18ed45f..24c6a7a 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ package:build cp $(BUILDPATH)/basics/libpaysages_basics.so* paysages3d-linux/lib/ cp $(BUILDPATH)/definition/libpaysages_definition.so* paysages3d-linux/lib/ cp $(BUILDPATH)/render/software/libpaysages_render_software.so* paysages3d-linux/lib/ - cp $(BUILDPATH)/render/preview/libpaysages_render_software.so* paysages3d-linux/lib/ + cp $(BUILDPATH)/render/preview/libpaysages_render_preview.so* paysages3d-linux/lib/ cp $(BUILDPATH)/render/opengl/libpaysages_render_opengl.so* paysages3d-linux/lib/ cp $(BUILDPATH)/interface/desktop/paysages-gui paysages3d-linux/lib/ chmod +x paysages3d-linux/lib/paysages-gui diff --git a/src/render/software/CloudBasicLayerRenderer.cpp b/src/render/software/CloudBasicLayerRenderer.cpp index 85ca4be..330cdd2 100644 --- a/src/render/software/CloudBasicLayerRenderer.cpp +++ b/src/render/software/CloudBasicLayerRenderer.cpp @@ -46,6 +46,7 @@ static inline double _getDistanceToBorder(BaseCloudsModel* model, Vector3 positi static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vector3 start, Vector3 direction, double, int max_segments, double max_inside_length, double max_total_length, double* inside_length, double* total_length, CloudSegment* out_segments) { CloudLayerDefinition* layer = model->getLayer(); + double ymin, ymax; int inside, segment_count; double current_total_length, current_inside_length; double step_length, segment_length, remaining_length; @@ -58,6 +59,8 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec return 0; } + model->getAltitudeRange(&ymin, &ymax); + render_precision = 15.2 - 1.5 * (double)renderer->render_quality; render_precision = render_precision * layer->scaling / 50.0; if (render_precision > max_total_length / 10.0) @@ -75,7 +78,7 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec segment_length = 0.0; walker = start; noise_distance = _getDistanceToBorder(model, start) * render_precision; - inside = (noise_distance > 0.0) ? 1 : 0; + inside = 0; step = direction.scale(render_precision); do @@ -132,7 +135,7 @@ static int _findSegments(BaseCloudsModel* model, SoftwareRenderer* renderer, Vec step = direction.scale((noise_distance > -render_precision) ? render_precision : -noise_distance); } } - } while (inside || (walker.y >= layer->altitude - 0.001 && walker.y <= (layer->altitude + layer->scaling) + 0.001 && current_total_length < max_total_length && current_inside_length < max_inside_length)); + } while (inside || (walker.y >= ymin - 0.001 && walker.y <= ymax + 0.001 && current_total_length < max_total_length && current_inside_length < max_inside_length)); *total_length = current_total_length; *inside_length = current_inside_length; @@ -169,8 +172,8 @@ Color CloudBasicLayerRenderer::getColor(BaseCloudsModel *model, const Vector3 &e SurfaceMaterial material; material.base = colorToHSL(Color(0.7, 0.7, 0.7)); material.hardness = 0.25; - material.reflection = 0.3; - material.shininess = 0.8; + material.reflection = 0.0; + material.shininess = 0.0; materialValidate(&material); col = parent->applyLightingToSurface(segments[i].start, parent->getAtmosphereRenderer()->getSunDirection(), material); diff --git a/src/render/software/CloudsRenderer.cpp b/src/render/software/CloudsRenderer.cpp index 9e13d67..e9635a2 100644 --- a/src/render/software/CloudsRenderer.cpp +++ b/src/render/software/CloudsRenderer.cpp @@ -90,6 +90,7 @@ BaseCloudLayerRenderer* CloudsRenderer::getLayerRenderer(unsigned int layer) } else { + qWarning("Asked for unknown layer renderer %d", layer); return fake_renderer; } } @@ -102,6 +103,7 @@ BaseCloudsModel* CloudsRenderer::getLayerModel(unsigned int layer) } else { + qWarning("Asked for unknown layer renderer %d", layer); return fake_model; } } @@ -149,7 +151,7 @@ bool CloudsRenderer::alterLight(LightComponent* light, const Vector3 &eye, const BaseCloudLayerRenderer* layer_renderer = getLayerRenderer(i); BaseCloudsModel* layer_model = getLayerModel(i); - altered = altered || layer_renderer->alterLight(layer_model, light, eye, location); + altered = layer_renderer->alterLight(layer_model, light, eye, location) || altered; } return altered; diff --git a/src/render/software/TerrainRasterizer.cpp b/src/render/software/TerrainRasterizer.cpp index 0fbb426..72b1e20 100644 --- a/src/render/software/TerrainRasterizer.cpp +++ b/src/render/software/TerrainRasterizer.cpp @@ -208,7 +208,7 @@ static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping) info->rasterizer->tessellateChunk(&info->chunk, info->chunk.detail_hint); } - free(data); + delete info; return 0; } diff --git a/src/render/software/WaterRasterizer.cpp b/src/render/software/WaterRasterizer.cpp index b09071b..2ec32d1 100644 --- a/src/render/software/WaterRasterizer.cpp +++ b/src/render/software/WaterRasterizer.cpp @@ -60,7 +60,7 @@ static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping) _renderQuad(info->renderer, info->cx - info->radius_ext, info->cz + info->radius_int - info->chunk_size * info->i, info->chunk_size); } - free(data); + delete info; return 0; } diff --git a/src/system/System.cpp b/src/system/System.cpp index bf531f8..1872bef 100644 --- a/src/system/System.cpp +++ b/src/system/System.cpp @@ -1,7 +1,6 @@ #include "System.h" #include -#include static int core_count = -1; @@ -9,12 +8,16 @@ int System::getCoreCount() { if (core_count < 0) { +#ifdef NDEBUG core_count = QThread::idealThreadCount(); if (core_count <= 0) { - qWarning() << "Can't find number of CPU cores, using only 1"; + qWarning("Can't find number of CPU cores, using only 1"); core_count = 1; } +#else + core_count = 1; +#endif } return core_count; }