[IGfxWorld] Test pointer duplication
This commit is contained in:
parent
85d519b7b0
commit
dbe0af988f
@ -31,25 +31,6 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
std::sort(surfs.begin(), surfs.end(), [](Game::GfxSurface* a, Game::GfxSurface* b)
|
|
||||||
{
|
|
||||||
if (a->material->name == nullptr && b->material->name == nullptr) return false;
|
|
||||||
if (a->material->name == nullptr && b->material->name != nullptr) return true;
|
|
||||||
if (a->material->name != nullptr && b->material->name == nullptr) return false;
|
|
||||||
return strcmp(a->material->name, b->material->name) == 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
Game::GfxSurface* tmpBuffer = builder->getAllocator()->allocateArray<Game::GfxSurface>(world->surfaceCount);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < world->surfaceCount; ++i)
|
|
||||||
{
|
|
||||||
std::memcpy(&tmpBuffer[i], surfs[i], sizeof(Game::GfxSurface));
|
|
||||||
}
|
|
||||||
|
|
||||||
asset->surfaces = tmpBuffer;
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (asset->surfacesBounds)
|
if (asset->surfacesBounds)
|
||||||
{
|
{
|
||||||
asset->surfacesBounds = reader->readArray<Game::GfxSurfaceBounds>(world->surfaceCount);
|
asset->surfacesBounds = reader->readArray<Game::GfxSurfaceBounds>(world->surfaceCount);
|
||||||
@ -66,7 +47,6 @@ namespace Assets
|
|||||||
if (model->model)
|
if (model->model)
|
||||||
{
|
{
|
||||||
model->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, reader->readString().data(), builder).model;
|
model->model = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_XMODEL, reader->readString().data(), builder).model;
|
||||||
//reader->readString(); model->model = Components::AssetHandler::FindOriginalAsset(Game::XAssetType::ASSET_TYPE_XMODEL, "void").model; // Use red-fx for now
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -997,6 +977,8 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->baseName);
|
Utils::Stream::ClearPointer(&dest->baseName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//buffer->setPointerAssertion(true);
|
||||||
|
|
||||||
if (asset->skies)
|
if (asset->skies)
|
||||||
{
|
{
|
||||||
AssertSize(Game::GfxSky, 16);
|
AssertSize(Game::GfxSky, 16);
|
||||||
@ -1364,6 +1346,7 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->heroOnlyLights);
|
Utils::Stream::ClearPointer(&dest->heroOnlyLights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//buffer->setPointerAssertion(false);
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
SaveLogExit();
|
SaveLogExit();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "STDInclude.hpp"
|
#include "STDInclude.hpp"
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
@ -87,7 +87,7 @@ namespace Utils
|
|||||||
return this->pointerMap.find(pointer) != this->pointerMap.end();
|
return this->pointerMap.find(pointer) != this->pointerMap.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream::Stream() : criticalSectionState(0)
|
Stream::Stream() : ptrAssertion(false), criticalSectionState(0)
|
||||||
{
|
{
|
||||||
memset(this->blockSize, 0, sizeof(this->blockSize));
|
memset(this->blockSize, 0, sizeof(this->blockSize));
|
||||||
|
|
||||||
@ -122,6 +122,25 @@ namespace Utils
|
|||||||
return this->buffer.capacity();
|
return this->buffer.capacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Stream::assertPointer(const void* pointer, size_t length)
|
||||||
|
{
|
||||||
|
if (!this->ptrAssertion) return;
|
||||||
|
|
||||||
|
for (auto& entry : this->ptrList)
|
||||||
|
{
|
||||||
|
unsigned int ePtr = reinterpret_cast<unsigned int>(entry.first);
|
||||||
|
unsigned int tPtr = reinterpret_cast<unsigned int>(pointer);
|
||||||
|
|
||||||
|
if(Utils::HasIntercection(ePtr, entry.second, tPtr, length))
|
||||||
|
{
|
||||||
|
MessageBoxA(nullptr, "Duplicate data written!", "ERROR", MB_ICONERROR);
|
||||||
|
__debugbreak();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->ptrList.push_back({ pointer, length });
|
||||||
|
}
|
||||||
|
|
||||||
char* Stream::save(const void* _str, size_t size, size_t count)
|
char* Stream::save(const void* _str, size_t size, size_t count)
|
||||||
{
|
{
|
||||||
return this->save(this->getCurrentBlock(), _str, size, count);
|
return this->save(this->getCurrentBlock(), _str, size, count);
|
||||||
@ -155,6 +174,7 @@ namespace Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->increaseBlockSize(stream, size * count);
|
this->increaseBlockSize(stream, size * count);
|
||||||
|
this->assertPointer(_str, size * count);
|
||||||
|
|
||||||
return this->at() - (size * count);
|
return this->at() - (size * count);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ namespace Utils
|
|||||||
class Stream
|
class Stream
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
bool ptrAssertion;
|
||||||
|
std::vector<std::pair<const void*, size_t>> ptrList;
|
||||||
|
|
||||||
int criticalSectionState;
|
int criticalSectionState;
|
||||||
unsigned int blockSize[Game::MAX_XFILE_COUNT];
|
unsigned int blockSize[Game::MAX_XFILE_COUNT];
|
||||||
std::vector<Game::XFILE_BLOCK_TYPES> streamStack;
|
std::vector<Game::XFILE_BLOCK_TYPES> streamStack;
|
||||||
@ -133,6 +136,12 @@ namespace Utils
|
|||||||
*object = reinterpret_cast<T*>(-1);
|
*object = reinterpret_cast<T*>(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPointerAssertion(bool value)
|
||||||
|
{
|
||||||
|
this->ptrAssertion = value;
|
||||||
|
}
|
||||||
|
void assertPointer(const void* pointer, size_t length);
|
||||||
|
|
||||||
void toBuffer(std::string& outBuffer);
|
void toBuffer(std::string& outBuffer);
|
||||||
std::string toBuffer();
|
std::string toBuffer();
|
||||||
|
|
||||||
|
@ -81,6 +81,6 @@ namespace Utils
|
|||||||
|
|
||||||
bool HasIntercection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2)
|
bool HasIntercection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2)
|
||||||
{
|
{
|
||||||
return !((base1 + len1) < base2 || (base2 + len2) < base1);
|
return !(base1 + len1 <= base2 || base2 + len2 <= base1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user