Fixes for crash bugs and memory corruption.

develop
Petr Mrázek 2010-02-25 17:37:40 +01:00
parent 230af4310f
commit de5b2ecb4e
5 changed files with 32 additions and 28 deletions

@ -992,21 +992,21 @@ bool API::ReadNote (const int32_t &index, t_note & note)
} }
bool API::InitReadSettlements( uint32_t & numsettlements ) bool API::InitReadSettlements( uint32_t & numsettlements )
{ {
memory_info * minfo = d->offset_descriptor; memory_info * minfo = d->offset_descriptor;
int allSettlements = minfo->getAddress ("settlements"); int allSettlements = minfo->getAddress ("settlements");
int currentSettlement = minfo->getAddress("settlement_current"); int currentSettlement = minfo->getAddress("settlement_current");
d->settlement_name_offset = minfo->getOffset ("settlement_name"); d->settlement_name_offset = minfo->getOffset ("settlement_name");
d->settlement_world_xy_offset = minfo->getOffset ("settlement_world_xy"); d->settlement_world_xy_offset = minfo->getOffset ("settlement_world_xy");
d->settlement_local_xy_offset = minfo->getOffset ("settlement_local_xy"); d->settlement_local_xy_offset = minfo->getOffset ("settlement_local_xy");
if (allSettlements && currentSettlement if (allSettlements && currentSettlement
&& d->settlement_name_offset && d->settlement_name_offset
&& d->settlement_world_xy_offset && d->settlement_world_xy_offset
&& d->settlement_local_xy_offset && d->settlement_local_xy_offset
) )
{ {
d->p_settlements = new DfVector (d->p->readVector (allSettlements, 4)); d->p_settlements = new DfVector (d->p->readVector (allSettlements, 4));
d->p_current_settlement = new DfVector(d->p->readVector(currentSettlement,4)); d->p_current_settlement = new DfVector(d->p->readVector(currentSettlement,4));
d->settlementsInited = true; d->settlementsInited = true;
numsettlements = d->p_settlements->getSize(); numsettlements = d->p_settlements->getSize();
return true; return true;
@ -1017,37 +1017,41 @@ bool API::InitReadSettlements( uint32_t & numsettlements )
numsettlements = 0; numsettlements = 0;
return false; return false;
} }
} }
bool API::ReadSettlement(const int32_t &index, t_settlement & settlement) bool API::ReadSettlement(const int32_t &index, t_settlement & settlement)
{ {
if(!d->settlementsInited) if(!d->settlementsInited)
return false;
if(!d->p_settlements->getSize())
return false; return false;
// read pointer from vector at position // read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_settlements->at (index); uint32_t temp = * (uint32_t *) d->p_settlements->at (index);
settlement.origin = temp; settlement.origin = temp;
g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name); g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x); g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1); g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true; return true;
} }
bool API::ReadCurrentSettlement(t_settlement & settlement) bool API::ReadCurrentSettlement(t_settlement & settlement)
{ {
if(!d->settlementsInited) if(!d->settlementsInited)
return false; return false;
if(!d->p_current_settlement->getSize())
return false;
uint32_t temp = * (uint32_t *) d->p_current_settlement->at(0); uint32_t temp = * (uint32_t *) d->p_current_settlement->at(0);
settlement.origin = temp; settlement.origin = temp;
g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name); g_pProcess->read(temp + d->settlement_name_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.name);
g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int32_t), (uint8_t *) &settlement.world_x); g_pProcess->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int32_t), (uint8_t *) &settlement.local_x1); g_pProcess->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
return true; return true;
} }
void API::FinishReadSettlements() void API::FinishReadSettlements()
{ {
delete d->p_settlements; delete d->p_settlements;
delete d->p_current_settlement; delete d->p_current_settlement;
d->p_settlements = NULL; d->p_settlements = NULL;
d->p_current_settlement = NULL; d->p_current_settlement = NULL;
d->settlementsInited = false; d->settlementsInited = false;
} }

@ -94,7 +94,12 @@ memory_info::memory_info(const memory_info &old)
d->hexvals = old.d->hexvals; d->hexvals = old.d->hexvals;
d->strings = old.d->strings; d->strings = old.d->strings;
d->base = old.d->base; d->base = old.d->base;
d->classes = old.d->classes; //d->classes = old.d->classes;
for(int i = 0; i < old.d->classes.size(); i++)
{
t_class * copy = new t_class(*old.d->classes[i]);
d->classes.push_back(copy);
}
d->classindex = old.d->classindex; d->classindex = old.d->classindex;
d->professions = old.d->professions; d->professions = old.d->professions;
d->jobs = old.d->jobs; d->jobs = old.d->jobs;
@ -107,7 +112,7 @@ memory_info::memory_info(const memory_info &old)
memory_info::~memory_info() memory_info::~memory_info()
{ {
// delete the vtables // delete the vtables
for(int i = 0; i < d->classes.size();i++) for(uint32_t i = 0; i < d->classes.size();i++)
{ {
delete d->classes[i]; delete d->classes[i];
} }

@ -72,6 +72,7 @@ namespace DFHack
{ {
delete subs[i]; delete subs[i];
} }
subs.clear();
} }
string classname; string classname;
uint32_t vtable; uint32_t vtable;

@ -476,10 +476,6 @@ bool SHMProcess::detach()
{ {
return false; return false;
} }
if(d->suspended)
{
resume();
}
// detach segment // detach segment
UnmapViewOfFile(d->my_shm); UnmapViewOfFile(d->my_shm);
// release it for some other client // release it for some other client

@ -68,9 +68,7 @@ bool ProcessEnumerator::findProcessess()
// Get the list of process identifiers. // Get the list of process identifiers.
DWORD ProcArray[2048], memoryNeeded, numProccesses; DWORD ProcArray[2048], memoryNeeded, numProccesses;
{ {
Process *p = new SHMProcess(d->meminfo->meminfo); Process * p = new SHMProcess(d->meminfo->meminfo);
delete p;
p = new SHMProcess(d->meminfo->meminfo);
if(p->isIdentified()) if(p->isIdentified())
{ {
d->processes.push_back(p); d->processes.push_back(p);