From 6f8e0c3cfda70decd3be1bfac2228999ae02c209 Mon Sep 17 00:00:00 2001 From: Michael Lemaire Date: Wed, 12 Aug 2015 19:29:28 +0200 Subject: [PATCH] Fixed some memory issues --- TODO | 54 +++++------------------ src/definition/BaseDefinition.cpp | 4 +- src/definition/BaseDefinition.h | 1 + src/definition/Layers.cpp | 1 + src/definition/PaintedGridData.cpp | 8 ++-- src/definition/TextureLayerDefinition.cpp | 3 ++ src/tests/BaseDefinition_Test.cpp | 21 +++++++++ 7 files changed, 44 insertions(+), 48 deletions(-) diff --git a/TODO b/TODO index 9185bd8..18ec120 100644 --- a/TODO +++ b/TODO @@ -1,58 +1,26 @@ -Technology Preview 2 : -- Add initial terrain offset so that the (0,0) coordinates are above water (to avoid starting at the middle of a sea). -- Use water height as 0.0 (offset the terrain). -- Add missing cloud models. -- Finish material dialog. -- Finish texture dialog. +Technlology Preview 2 : +- Rewrite UI in QtQuick, with full-window OpenGL editor. +- Streamline the definition system, with undo and events. +- Implement copy-on-write on definitions (to avoid copying whole heightmaps for instance). +- Add clouds to OpenGL with 3d textures. +- Fix potential holes in land rendering (OpenGL and software). + +Technology Preview 3 : +- Alter aerial perspective using estimation of the amount of light left after cloud layers traversal. - Fix rendering when inside a cloud layer, with other upper or lower layers. - Fix the moon being backlit by its own light. -- Translations. - -Technlogy Preview 3 : -- FOCUS : Streamlining, with undo system -- FOCUS : Vegetation -- Implement copy-on-write on definitions (to avoid copying whole heightmaps for instance). -- Alter aerial perspective using estimation of the amount of light left after cloud layers traversal. -- Add a map preview to terrain editor. -- Better time selection widget for atmosphere. - Clouds should keep distance to ground. -- Fully move layer management from BaseForm to BaseFormLayer. - Allow render saving in HDR compatible format. -- Add clouds to explorer with 3d textures. - Add fresnel effect to specular lighting. - Add shadow control ("minimum lighting") to material. - Start using OpenCL to optimize rendering. -- Fully restore render progress (with first pass). -- Rethink the quality settings and detail smoothing in the distance. - => When quality setting is set to 10, add boost options - => Add detail boost (adds granularity) - => Add step boost (for marching algorithms) -- Add logarithmic sliders for some float values. -- Improve previews. - => Add user markers on OSD. - => Add areas marking. -- Add a noise automatic filler. -- Lock some previews together (eg: terrain height and colored preview). -- Find a new licence. Technology Preview 4 : - Implement Sub Surface Scattering for water, textures and clouds. - Implement earth curvature. - Use bicubic interpolation for antialiasing. -- Allow for larger renders/antialias (will need several two-pass chunks). -- Add a progress indicator on previews. -- Mark modified tabs and ask for losing modifications (idem for layers). -- Fix potential holes in land rendering. -- Progressive final render (increasing resolution, for second pass only). -- Improve 3d explorer - => Restore LOD and intelligent poly count (and raise max tessellation) - => Better handling of high altitude - => Interrupt chunk rendering when quitting dialog - => Don't display the water if it's below all ground - => Try to overcome the near frustum cutting - => Add toggles (for water...) - => Max texture size should depend on GPU memory available -- Interrupt preview chunk renderings that will be discarded at commit, or that are no more visible. +- Add translations. +- Find a new licence. Release Candidate : - Polish all features and UI. diff --git a/src/definition/BaseDefinition.cpp b/src/definition/BaseDefinition.cpp index 8a7f942..9a194cc 100644 --- a/src/definition/BaseDefinition.cpp +++ b/src/definition/BaseDefinition.cpp @@ -24,7 +24,9 @@ BaseDefinition::~BaseDefinition() parent = NULL; } - for (auto child:children) + // Work on a copy, because the child destructor will modify the array by removing itself using removeChild + std::vector children_copy = children; + for (auto child:children_copy) { if (child->getParent() == this) { diff --git a/src/definition/BaseDefinition.h b/src/definition/BaseDefinition.h index 76c8a86..7193709 100644 --- a/src/definition/BaseDefinition.h +++ b/src/definition/BaseDefinition.h @@ -28,6 +28,7 @@ public: inline const BaseDefinition* getParent() const {return parent;} inline const BaseDefinition* getRoot() const {return root;} + inline int getChildrenCount() const {return children.size();} /** * Return a string representation of the tree (mainly for debugging purposes). diff --git a/src/definition/Layers.cpp b/src/definition/Layers.cpp index 27dd6d1..33358f7 100644 --- a/src/definition/Layers.cpp +++ b/src/definition/Layers.cpp @@ -92,6 +92,7 @@ int Layers::addLayer(BaseDefinition* layer) else { logWarning("Add layer ignored because limit of %d reached", max_layer_count); + delete layer; return -1; } } diff --git a/src/definition/PaintedGridData.cpp b/src/definition/PaintedGridData.cpp index f0359a1..cd6a753 100644 --- a/src/definition/PaintedGridData.cpp +++ b/src/definition/PaintedGridData.cpp @@ -6,14 +6,14 @@ PaintedGridData::PaintedGridData() { rows_count = 0; - rows = new HeightMapRow[1]; + rows = (HeightMapRow *)malloc(sizeof(HeightMapRow)); memsize = 0; } PaintedGridData::~PaintedGridData() { clear(); - delete[] rows; + free(rows); } void PaintedGridData::copy(PaintedGridData *destination) const @@ -119,7 +119,7 @@ void PaintedGridData::clear() free(rows[i].pixel_groups); } rows_count = 0; - delete[] rows; - rows = new HeightMapRow[1]; + free(rows); + rows = (HeightMapRow *)malloc(sizeof(HeightMapRow)); memsize = 0; } diff --git a/src/definition/TextureLayerDefinition.cpp b/src/definition/TextureLayerDefinition.cpp index ebf3688..1da881f 100644 --- a/src/definition/TextureLayerDefinition.cpp +++ b/src/definition/TextureLayerDefinition.cpp @@ -14,6 +14,9 @@ TextureLayerDefinition::TextureLayerDefinition(BaseDefinition* parent): _displacement_noise = new NoiseGenerator; _detail_noise = new NoiseGenerator; material = new SurfaceMaterial; + + displacement_height = 0.0; + displacement_scaling = 1.0; } TextureLayerDefinition::~TextureLayerDefinition() diff --git a/src/tests/BaseDefinition_Test.cpp b/src/tests/BaseDefinition_Test.cpp index 6e2e269..c046fc9 100644 --- a/src/tests/BaseDefinition_Test.cpp +++ b/src/tests/BaseDefinition_Test.cpp @@ -12,3 +12,24 @@ TEST(BaseDefinition, toString) EXPECT_EQ("root\n branch\n leaf1\n leaf2", root.toString()); EXPECT_EQ("branch\n leaf1\n leaf2", branch.toString()); } + +TEST(BaseDefinition, attachDetach) +{ + BaseDefinition* root = new BaseDefinition(NULL, "root"); + BaseDefinition* child1 = new BaseDefinition(root, "child1"); + BaseDefinition* child2 = new BaseDefinition(root, "child2"); + + EXPECT_EQ(root, child1->getParent()); + EXPECT_EQ(root, child2->getParent()); + EXPECT_EQ(2, root->getChildrenCount()); + + delete child1; + + EXPECT_EQ(1, root->getChildrenCount()); + + delete child2; + + EXPECT_EQ(0, root->getChildrenCount()); + + delete root; +}