Jump to content
  • Advertisement
Sign in to follow this  
yogeshpatel4all

Memory Allocation Problem

This topic is 4863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I have 10 objects . I m allocaing memory to each of them . Memory is allocted properly . But when i m destroying objects ( i m destroying it in reverse order ) it allows me to destroy only Some objects and gives the following error If this ASSERT fails, a bad pointer has been passed in. It may be totally bogus, or it may have been allocated from another heap. The pointer MUST come from the 'local' heap. if u know anything about this error , help me.

Share this post


Link to post
Share on other sites
Advertisement
Can you show/explain how you are allocating and deallocating the memory as well as what the data type is. A little code would be best.

Share this post


Link to post
Share on other sites
Init()
{

/* This is just in brief what my code is doing */

A , B , C , D , E are classes

other objects r also initialized befor this ..

Object_A = new ( A );
Object_B = new ( B );
Object_C = new ( C );
Object_D = new ( D );
Object_E = new ( 7 * sizeof ( E ) );

if i m deallocating memory here only then
it allows me to deallocate .

But If i run the program and trying to deallocate the memory
when program exits ,
that is after Update() and Render()
then it gives error while deallocating certain objects .

delete A ; // It will deallocate
delete B ; // It will deallocate
delete C ; // It is giving error
delete D ; // It is giving error
delete E[] ; // It is giving error

A bad pointer has been passed in. It may be
totally bogus, or it may have been allocated from another heap.
The pointer MUST come from the 'local' heap.

i have checked the pointer adrresses also they r same
while allocating and deallocating
}

Share this post


Link to post
Share on other sites
I assume that for Object_E you are trying to allocate an array:


//allocating
Object_A = new A;
Object_B = new B;
Object_C = new C;
Object_D = new D;
Object_E = new D[7];

//de-allocating
delete A ;
delete B ;
delete C ;
delete D ;
delete E[] ;



That should do it :)

Share this post


Link to post
Share on other sites
Don't you mean...


//allocating
Object_A = new A;
Object_B = new B;
Object_C = new C;
Object_D = new D;
Object_E = new E[7];

//de-allocating
delete Object_A ;
delete Object_B ;
delete Object_C ;
delete Object_D ;
delete [] Object_E ;


?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!