Archived

This topic is now archived and is closed to further replies.

Allebarde

VC++ problem

Recommended Posts

Allebarde    122
Hi! When I run my program I get this error: Debug Assertion Failed! Program: Path of my program File: dbgdel.cpp Line : 47 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the VC++ documentation on asserts What is it exactly? Shall I disable something? I don''t know what to do .. Please Help ) Bye

Share this post


Link to post
Share on other sites
cgoat    132
Looks like you''re trying to get from an empty list or something.

Try running the program in the debugger and stepping through your code to find where it''s causing the error.

Share this post


Link to post
Share on other sites
Luctus    584
You're doign a linked list or something similar, right? I made a linked tree and got that error when deleting nodes. I have looked through my code several time and it doesn't seem to be any problem with it. My guess is that it's micro$oft who messed up.

Anyway, if you compile with release instead of debug mode, it will work.

If anyone knows what's wrong and how to fix it without compiling in release mode (since debug could be pretty handy at times) me too would like to know.

[edited by - Luctus on April 30, 2002 12:47:55 PM]

Share this post


Link to post
Share on other sites
Sneftel    1788
Erm, I''m pretty sure VC++ doesn''t have any bugs regarding assertions. They aren''t especially complex things, so they tend to either work or not.

Perhaps you could post your code?

Share this post


Link to post
Share on other sites
Allebarde    122
I think I found the problem: The error occurs when I do:
delete CurrentChunks;
This releases some memory, and the error occurs depending of the 3DS model I want to load..

Share this post


Link to post
Share on other sites
Luctus    584
quote:
Original post by Sneftel
Erm, I''m pretty sure VC++ doesn''t have any bugs regarding assertions. They aren''t especially complex things, so they tend to either work or not.

Perhaps you could post your code?


Hm..let''s say, I think it''s strange I get an assertion error since I''m not even using any assertion functions in my code.

-Luctus

Share this post


Link to post
Share on other sites
cgoat    132
quote:
Original post by Luctus
Hm..let''s say, I think it''s strange I get an assertion error since I''m not even using any assertion functions in my code.



This means that you''re passing bad arguments to a system function that has an assert in it to check. If you ignore that and compile in Release mode to get rid of the assert, it''s no longer going to check what you pass in, and your results are going to be undefined. Meaning that your program will probably crash what appears to be "randomly".

Fix the error, don''t ignore it.

Share this post


Link to post
Share on other sites
Dire.Wolf    122
It has to do with memory deallocation. When you compile your code in debug mode new/delete are handled differently than in release mode. A linked list of valid memory blocks is built up and released throughout your programs life time. If you call delete on an invalid pointer you get this assertion. This assertion can also happen in other circumstances too.

Make sure your variable "CurrentChunks" is pointing to a valid memory location before you try and delete it. It is your bug, not VCs...

Dire Wolf
www.digitalfiends.com

Share this post


Link to post
Share on other sites
Allebarde    122
Hi!
I have again Memory problems :
The error occured when I did a delete CurrentChunck..
In fact using debug I found where exactly the error was:


Model3ds.pObject[Model3ds.numOfObjects - 1];
Model3ds.numOfObjects++;

//HERE NO PROBLEMS : CurrentChunk is not modified

//allocate some memory
*( &Model3ds.pObject + (Model3ds.numOfObjects-1)*sizeof(Object3DS) ) = new(Object3DS);

//CurrentChunk is not Modified

// Initialize the object and all it''s data members
memset(&(Model3ds.pObject[Model3ds.numOfObjects - 1]), 0, sizeof(Object3DS));

//HERE PROBLEM: CurrentChunck is modified

// Get the name of the object and store it
CurrentChunck->bytesRead += SearchString(Model3ds.pObject[Model3ds.numOfObjects - 1].strName);

Apparately the problem occurs when I set the memory to 0 with memset..
A friend who''s coding under DOS, has the same problem: Can someone help us?
Thanks

Share this post


Link to post
Share on other sites
dalleboy    324
Why do you do a memset on the newly created object? Couldn''t the constructor zero all its members instead? If the class contain virtual methods this could be dangerous as you would nullify the vtable (am I right). If the class contain members of other classes that have pointers and or virtual methods this could also be dangerous.

Share this post


Link to post
Share on other sites
Allebarde    122
here''s SearchString:

int _3DS::SearchString(char* string)
{
char ReadCaracters=0;

fread(string,1,1,FilePtr);

while (*(string + ReadCaracters++) !=0)
{
fread( (string + ReadCaracters) ,1,1, FilePtr);
}
return (strlen(string) + 1);
}

I allocate in my code, some memory for Object3DS. This is a structure, who contains variables and pointers. There''s no constructor, this is why I set the new structure allocated to 0 with memset.
Is it better?

Share this post


Link to post
Share on other sites
dalleboy    324
Off topic but why are you doing like this:
*(&Model3ds.pObject + (Model3ds.numOfObjects - 1) * sizeof(Object3DS)) = new(Object3DS);

When it would be easier to read this:
Model3ds.pObject[Model3ds.numOfObjects - 1] = new Object3DS;

Share this post


Link to post
Share on other sites
Allebarde    122
I use CurrentChunck to Read my 3DS file.

struct CHUNCK
{
unsigned short int ID; // The chunk''s ID
unsigned int length; // The length of the chunk
unsigned int bytesRead; // The amount of bytes read within that chunk
};

Share this post


Link to post
Share on other sites
Allebarde    122
Yes!
It points on CHUNCK:
CHUNCK* CurrentChunck;

I allocate a lot of times CurrentChunck.

But In fact, before The code was working.

I have made a Class to load my 3ds files, and now I have problems..
I''m sure: I didn''t change anything except one thing: Model3ds is not a pointer to a structure but something declared like that in my class:

Model3DS Model3ds;

I tried to change my code, so as to use a pointer declared like that:

Model3DS *Model3ds;
But it didn''t work either.

Share this post


Link to post
Share on other sites
dalleboy    324
Remove the & in the memset call else you are writing to the wrong place in the memory, perhaps...

memset(Model3ds.pObject[Model3ds.numOfObjects - 1], 0, sizeof(Object3DS));

Share this post


Link to post
Share on other sites
Allebarde    122
It doesn''t work
Model3ds.pObject[Model3ds.numOfObjects-1] = new Object3DS; doesn''t work either

Since I use this class, all goes bad.

Is it possible that VC++ allocates memory over memory already allocated?

Share this post


Link to post
Share on other sites
Allebarde    122
Object3DS* pObject;
It allocates memory during the program

*( &Model3ds.pObject + (Model3ds.numOfObjects-1)*sizeof(Object3DS) ) = new(Object3DS);

Share this post


Link to post
Share on other sites
dalleboy    324
Read these topics:

http://www.gamedev.net/community/forums/topic.asp?topic_id=91589
http://www.gamedev.net/community/forums/topic.asp?topic_id=90281

Share this post


Link to post
Share on other sites
dalleboy    324
That is what you are doing wrong. Object3DS* can hold a pointer to a Object3DS array or a single Object3DS object. It cannot hold an array of Object3DS pointers.

If you do like this:

Object3DS* pObject = new Object3DS[100];

That array will hold 100 Object3DS objects. Then you could memset the entire array, by:

memset(pObject, 0, 100 * sizeof(Object3DS));

Share this post


Link to post
Share on other sites