Skip to main content
gamedev.net
🔒 Locked

Debug Assertion Failed (runtime error)

Started by Nachiketa 5 replies 1.7k views
Original Post
Nachiketa
Nachiketa
Hello everyone. I am working on a small game (student project) and I am getting a runtime error :- "Debug Assertion Failed. dbgdel.cpp line 47" "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" The top of the call stack looks like :- CreateDevice.exe!operator delete(void * pUserData=0x076ebf48) Line 52 + 0x51 bytes C++ CreateDevice.exe!std::allocator::deallocate(double * _Ptr=0x076ebf48, unsigned int __formal=6) Line 141 + 0x9 bytes C++ CreateDevice.exe!std::vector >::_Tidy() Line 1098 C++ CreateDevice.exe!std::vector>::~vector >() Line 547 C++ CreateDevice.exe!Neuron::~Neuron() Line 32 + 0x12 bytes C++ CreateDevice.exe!Neuron::`scalar deleting destructor'() + 0x14 bytes C++ CreateDevice.exe!std::_Destroy(Neuron * _Ptr=0x076e07b0) Line 61 C++ CreateDevice.exe!std::allocator::destroy(Neuron * _Ptr=0x076e07b0) Line 161 + 0x9 bytes C++ CreateDevice.exe!std::_Destroy_range >(Neuron * _First=0x076e07b0, Neuron * _Last=0x076e0840, std::allocator & _Al={...}, std::_Nonscalar_ptr_iterator_tag __formal={...}) Line 235 + 0xc bytes C++ CreateDevice.exe!std::_Destroy_range >(Neuron * _First=0x076e07b0, Neuron * _Last=0x076e0840, std::allocator & _Al={...}) Line 226 + 0x28 bytes C++ CreateDevice.exe!std::vector >::_Destroy(Neuron * _First=0x076e07b0, Neuron * _Last=0x076e0840) Line 1083 + 0x14 bytes C++ CreateDevice.exe!std::vector >::erase(std::_Vector_iterator > _First={m_uiNumInputs=6 m_vecWeight=[0]() }, std::_Vector_iterator > _Last={m_uiNumInputs=-33686019 m_vecWeight=[3760332834](...,...) }) Line 1024 C++ CreateDevice.exe!std::vector >::clear() Line 1035 + 0x48 bytes C++ CreateDevice.exe!NeuralNetworkLayer::~NeuralNetworkLayer() Line 85 C++ The code where the error pops-up is in a loop. The error is encountered in the second iteration (which I find a little weird). I am using MSVC++ 2005 express and DirectX 9 (oct 2005). Please somebody shed some light on it. Thanx. PS - I can paste code snippets on request or mail the whole code.
ldeej
ldeej
It seems like you are deleting memory that was never allocated (uninitialized pointer), or data that was already deleted (dangling pointer)

Maybe Neurons point to data that you are trying to delete and has already been deleted?
Antheus
Antheus
You're deleting an invalid pointer.

It's pointing to wrong address.
It was deleted already, but not NULLed.
You're deleting an unitializaed pointer that is not NULL.
The pointer's memory has been corrupted by buffer overrun.

What is weird is that I don't see any dynamically allocated data in there. So it's most likely the last possibility.

You're probably overruning the std::vector, but that's the best I can tell.

Show the Neuron source code that accesses the vectors.

TheBlackVegetable
TheBlackVegetable
It probably isn't what's wrong with your code, but I've had a similar thing happen when I accidentally trashed some memory by dereferencing a pointer to a deleted object and calling one of its methods. The effects of that didn't show up until much later when some static std::set's containing pointers to the same object were destroyed, when exiting the program.

It just goes to show, you've got to be careful when sharing pointers between objects. It also means that the problem could be almost anywhere. I'd take a look at NeuralNetworkLayer, if it is new'd then maybe you are deleting it twice?
Nachiketa
Nachiketa
Thank you all for replying.

@ Antheus

Here's the source code where where Neuron's vector(of doubles) is accessed :-

vector NeuralNetwork::Update(vector &inputs)
{
// stores the resultant outputs from each layer
vector outputs;

int cWeight = 0;

// first check that we have the correct amount of inputs
if (inputs.size() != m_NumInputs)
{
// just return an empty vector if incorrect.
return outputs;
}

// For each layer
for (int i=0; i {
if ( i > 0 )
{
inputs = outputs;
}

outputs.clear();
cWeight = 0;

// for each neuron, sum the (inputs * corresponding weights).Throw
// the total at sigmoid function to get the output.
for (int j=0; j {
double netinput = 0;
int NumInputs = m_vecLayers.at(i).GetNeuronArray()[j].GetNumInputs();

// for each input
for (int k=0; k {
// sum the (weights * inputs)
netinput += m_vecLayers.at(i).GetNeuronArray()[j].GetWeights()[k] * inputs[cWeight++];
}

// add in the bias
netinput += m_vecLayers.at(i).GetNeuronArray()[j].GetWeights()[NumInputs-1] * Params::dBias;

// store the outputs from each layer as they are generated.
// The combined activation is first filtered through the sigmoid function
outputs.push_back(Sigmoid(netinput, Params::dActivationResponse));

cWeight = 0;
}
}
return outputs;
}

@ TheBlackVegetable

If you are asking me to look at NeuralNetworkLayer based on the call stack then I think I should provide you with more information. Earlier I gave you the first few lines(from the top). The last few lines of the call stack(bottom) go like this :-

CreateDevice.exe!NPCRobot::~NPCRobot() + 0x17 bytes C++

CreateDevice.exe!Controller::~Controller() Line 63 + 0x33 bytes C++

CreateDevice.exe!Render(RobotControl eUserRobot=DEFAULT, RobotControl eRobotNPC=FORWARD, Controller rController={...}) Line 542 + 0xf bytes C++

CreateDevice.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, HINSTANCE__ * __formal=0x00000000, HINSTANCE__ * __formal=0x00000000) Line 853 + 0x2d bytes C++

CreateDevice.exe!__tmainCRTStartup() Line 315 + 0x35 bytes C

CreateDevice.exe!WinMainCRTStartup() Line 187 C



Moreover, I have not used "new" anywhere in my code. The only dynamic allocations are the allocation of data to these vectors.

Eagerly waiting for your replies.
Nachiketa
Nachiketa
On further investigation I found out:

In the first iteration, class controller's destructor is called. It in turn calls the destructor for "vector" 4 times. In the second iteration, when the vector's destructor is called for the 3rd time, the app crashes with the error message. Any ideas ??
Nachiketa
Nachiketa
Thanx to everyone who responded.

The problem wastraced to a pointer being deleted twice. I had to modify the code design and the error went away.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.