Sign in to follow this  
WuTz

"new" fails. [c++]

Recommended Posts

Hello! I am totally confused. The Map-Loading code of my engine seems to fail at a really stupid location. The loader loads the Object-Class-IDs, like WTexture or WMesh, and creates the right class via "new". This worked fine, before I built in a new class for textures. Its not the problem that this class fails every time, no. It works fine, too, but this makes the problem so stupid: Here is what the loader does:
Load Class Num -> Mesh
Create Object from Class Num -> Obj=new WMesh;
Load Content -> OK.

--- Next object --- 

Load Class Num -> Shader
Create Object from Class Num -> Obj=new WShader;
Load Content -> OK.

--- Next object --- 

Load Class Num -> Texture (!!!)
Create Object from Class Num -> Obj=new WTexture; (WORKS FINE!!!!!!)
Load Content -> OK. 


--- Next object --- 

Load Class Num -> Mesh
Create Object from Class Num -> Obj=new WMesh;
Load Content -> OK. 

--- Next object --- 

Load Class Num -> Texture (!!! The second one !!!)
Create Object from Class Num -> Obj=new WTexture; (<--- Fails with std::bad_alloc Why???)
Load Content -> ---. 

Here is the piece of code which creates the new object:
case WTEXTURE:
   *Out=new WTexture;
return true;

Nothing special here! But why does it fail!? It's not that I don't have enougth RAM, if you think that... help me! :(

Share this post


Link to post
Share on other sites
Can we see the constructor for WTexture? It is more likely that something in the construction process is causing the bad_alloc. Likely suspects are things like dodgy dynamic array sizes or sizes for std::vectors etc.

Share this post


Link to post
Share on other sites
I checked this allready. But here you are:


WTexture::WTexture()
{
MyClass=WTEXTURE;
}

WTexture::~WTexture()
{

}



And remember: It works for the first time. When you need more code, just ask :)

EDIT:

Here is the full error output from VC: (Translated from german)


One exception (first Chance) at 0x77388915 in WTech DX10.exe: 0xC0000005: access violation (I don't know the word :) ) at 0x01e6ff78.
One exception (first Chance) at 0x774e42eb in WTech DX10.exe: Microsoft C++-exception : std::bad_alloc at memorylocation 0x0012e7f4..
unhandled exception at 0x774e42eb in WTech DX10.exe: Microsoft C++-exception : std::bad_alloc at memorylocation 0x0012e7f4..


This all is written by "new". Hope that helps...

Share this post


Link to post
Share on other sites
You probably have a buffer overflow in another buffer previously allocated that is causing corruption in the linked lists malloc() is using.

Overload all of the global new/delete operators and for each allocation, use malloc() to allocate 1,024 bytes extra beyond what is actually requested. If the error goes away, it is because you have given your buffer overflow enough padding that it no longer destroys the internal linked list required for allocations. You can work on solving the problem from there.


L. Spiro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this