From 09b4f29944e263c658bbf29b479096f8a3d29488 Mon Sep 17 00:00:00 2001 From: cutealien Date: Mon, 30 Nov 2009 14:51:59 +0000 Subject: [PATCH] Bugfix: irrArray should no longer crash when using other allocators. Corresponding test added. This was caused because operator= and copy-constructor where not called because the the second template parameters was not used in those function declarations and so only functions for the default parameter had been created. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2949 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 2 ++ include/irrArray.h | 8 +++--- tests/main.cpp | 1 + tests/testArray.cpp | 46 ++++++++++++++++++++++++++++++++++ tests/tests-last-passed-at.txt | 2 +- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 tests/testArray.cpp diff --git a/changes.txt b/changes.txt index 2a2415d1..3a11c566 100644 --- a/changes.txt +++ b/changes.txt @@ -1,5 +1,7 @@ Changes in 1.7 + - Bugfix: irrArray should no longer crash when using other allocators. + - Add MaterialViewer example. - Checkbox uses now disabled text color when disabled. diff --git a/include/irrArray.h b/include/irrArray.h index 3f74faa8..d74cf848 100644 --- a/include/irrArray.h +++ b/include/irrArray.h @@ -42,7 +42,7 @@ public: //! Copy constructor - array(const array& other) : data(0) + array(const array& other) : data(0) { *this = other; } @@ -247,7 +247,7 @@ public: //! Assignment operator - void operator=(const array& other) + void operator=(const array& other) { strategy = other.strategy; @@ -271,7 +271,7 @@ public: //! Equality operator - bool operator == (const array& other) const + bool operator == (const array& other) const { if (used != other.used) return false; @@ -284,7 +284,7 @@ public: //! Inequality operator - bool operator != (const array& other) const + bool operator != (const array& other) const { return !(*this==other); } diff --git a/tests/main.cpp b/tests/main.cpp index bf73120c..ec125dfd 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -52,6 +52,7 @@ int main(int argumentCount, char * arguments[]) TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory. // Now the simple tests without device + TEST(testArray); TEST(exports); TEST(irrCoreEquals); TEST(testIrrString); diff --git a/tests/testArray.cpp b/tests/testArray.cpp new file mode 100644 index 00000000..f567b54c --- /dev/null +++ b/tests/testArray.cpp @@ -0,0 +1,46 @@ +// Copyright (C) 2008-2009 Colin MacDonald +// No rights reserved: this software is in the public domain. + +#include "testUtils.h" +#include +#include + +using namespace irr; +using namespace core; + +struct VarArray +{ + core::array < int, core::irrAllocatorFast > MyArray; +}; + +// this will (did once) simply crash when wrong, so no return value +void crashTestFastAlloc() +{ + core::array < VarArray, core::irrAllocatorFast > ArrayArray; + ArrayArray.setAllocStrategy(core::ALLOC_STRATEGY_SAFE); // force more re-allocations + VarArray var; + var.MyArray.setAllocStrategy(core::ALLOC_STRATEGY_SAFE); // force more re-allocations + var.MyArray.push_back( 0 ); + + for ( int i=0; i< 100; ++i ) + { + ArrayArray.push_back(var); + ArrayArray.push_back(var); + } +} + +// Test the functionality of core::array +bool testArray(void) +{ + bool allExpected = true; + + logTestString("crashTestFastAlloc\n"); + crashTestFastAlloc(); + + if(allExpected) + logTestString("\nAll tests passed\n"); + else + logTestString("\nFAIL!\n"); + + return allExpected; +} diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 12132f8b..aec51631 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,2 +1,2 @@ -Test suite pass at GMT Mon Nov 30 14:06:12 2009 +Test suite pass at GMT Mon Nov 30 14:42:09 2009