I can't seem to pinpoint the cause

This commit is contained in:
Kayne Ruse
2015-04-26 03:11:00 +10:00
parent 7aeabf0d14
commit 63e4394583
9 changed files with 83 additions and 26 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=.
INCLUDES+=. ../map
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+34
View File
@@ -0,0 +1,34 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "region_checksum.hpp"
int debugRegionSum(Region* const region) {
int sum = 0;
for(int i = 0; i < REGION_WIDTH; i++) {
for (int j = 0; j < REGION_HEIGHT; j++) {
for (int k = 0; k < REGION_DEPTH; k++) {
sum += region->GetTile(i, j, k);
}
}
}
return sum;
}
+30
View File
@@ -0,0 +1,30 @@
/* Copyright: (c) Kayne Ruse 2013-2015
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef REGIONCHECKSUM_HPP_
#define REGIONCHECKSUM_HPP_
#include "region.hpp"
//fails if the result is 0
int debugRegionSum(Region* const);
#endif
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. ../utilities
INCLUDES+=. ../debugging ../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+5
View File
@@ -25,6 +25,8 @@
#include <cstring>
#include <stdexcept>
#include <iostream>
int snapToBase(int base, int x) {
return floor((double)x / base) * base;
}
@@ -39,6 +41,9 @@ Region::Region(int argX, int argY): x(argX), y(argY) {
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
solid = rhs.solid;
//debugging
std::cout << "Moved: (" << x << ", " << y << "): " << int(***tiles) << ", " << int(***rhs.tiles) << std::endl;
}
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
+6
View File
@@ -21,6 +21,8 @@
*/
#include "region_pager_base.hpp"
#include "region_checksum.hpp"
#include <stdexcept>
#include <algorithm>
@@ -70,7 +72,11 @@ Region* RegionPagerBase::FindRegion(int x, int y) {
}
Region* RegionPagerBase::PushRegion(Region* const ptr) {
//BUG: Lists seem to not work properly
regionList.push_front(*ptr);
if (debugRegionSum(&regionList.front())) {
throw(std::runtime_error("Checksum fail; RegionPagerBase::PushRegion()"));
}
return &regionList.front();
}