Please show us the piece of code ;-)
(The error probably is either on of: 1) the variable was not initialized, 2) does not point to memory allocated on the heap, 3) it is on the heap, but not an array, 4) double free. Hard to guess, though.)
Please show us the piece of code ;-)
(The error probably is either on of: 1) the variable was not initialized, 2) does not point to memory allocated on the heap, 3) it is on the heap, but not an array, 4) double free. Hard to guess, though.)
Heh, I didn't expect you to guess thoughThe complete code is available in the link in the first post: http://code.google.com/p/mll/source/checkout
It's not a terrible lot though. The place where it is going wrong is where I delete[] name and material_path, although the corruption is probably happening before that.
you create a vector of num_materials elements, and then add with push_back. That way you end up with a vector of 2x num_materials elements, I think.
Probably you want to call reserve, instead.
side note:
These checks are not useful. Don't hurt either, though.Qt Code:
if( materials != NULL ) delete materials;To copy to clipboard, switch view to plain text mode
You allocate materials as a pointer to std::vector, but free it as an array with delete[].
Change that to delete and you should be ok.
HTH
i) delete NULL is absolutely fine (just as free(NULL))
ii) When I browsed your svn repository online, I found such a line.
But it is not there. Perhaps I somehow git into an older revision. Sorry.
Any issues left?
Well, the program is still crashing on some files. I don't know why though, it does it when I call delete <var>. It differs per file. Sometimes it happens when I am deleting the normal_idx array, etc. I hesitate to use vectors, since with many allocations of models it would, I feel, introduce unwelcome memory usage - especially since there is no need to dynamically grow the arrays.
I'm trying to track it down now, although it may take a while. I'm learning a lot from it though, so I don't really mind too much, as long as it doesn't take too long![]()
Oh God, what a stupid mistake
Qt Code:
else if( buffer.substr( 0, 1 ) == "o" ){ name = new char[buffer.length() - 2]; sscanf(buffer.c_str(), "o %s", name);To copy to clipboard, switch view to plain text mode
I was allocating like that for certain variables. But I was not allowing space for the terminating \0 like that. It should have been buffer.length() - 1, obviously.
Bookmarks