Originally Posted by
WakkiTabakki
Code:
vector<myClass*> myVector; // This just allocates a pointer to a vector object
myVector = new vector<myClass*>(); // This would allocate the actual object,. and ofcourse assign the objects address to the pointer...
Well here's what I attempted:
Code:
client.h:
class client {
private:
vector<object3d*> partMasterList;
};
clientBasic.cpp:
client::setPartList() {
partMasterList = new vector<object3d*>();
}
and here's what compiler gave me:
Code:
g++ src/clientBasic.cpp -g -c -o obj/clientBasic.o -lGL -lSDL -lGLU -lSDL_net `sdl-config --cflags` `pkg-config --cflags ftgl`
src/clientBasic.cpp: In member function ‘void client::setPartList(const char*)’:
src/clientBasic.cpp:213: error: no match for ‘operator=’ in ‘((client*)this)->client::partMasterList = (((std::vector<object3d*, std::allocator<object3d*> >*)operator new(12u)), (<statement>, <anonymous>))’
/usr/include/c++/4.3/bits/vector.tcc:144: note: candidates are: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = object3d*, _Alloc = std::allocator<object3d*>]
make: *** [obj/clientBasic.o] Error 1
Can you even call new to non-pointer variables like in that vector allocator? I thought that was for dynamic memory allocation which would require pointers which myVector isn't though might be wrong.
Note that object3d has constructor which doesn't take parameters(though I only use one with parameters myself).
Oh and totally unrelated but have to vent a bit: STUPID WAVEFRONT! You have all the letters available and yet have to put 2 different formats to one letter in .obj file? Gee. Wondered why there's odd outputs in my converter which turns bunch of .obj files to own file format(that gets rid of few redundant data which previous files from animation gave me already and packs full animation to one file. Nothing fancy but just bit of restructuring of data to be more suitable for my needs). Well I looked at .obj file more closely and sure enough after whole bunch of f x/x/x x/x/x x/x/x lines there was f x x line. Gee. What the heck is that doing there? Now I need to figure out how to filter those ones out. No wonder output was all weird...Couldn't they have implemented line(I presume that's line and numbers are vertex and vertex) to be under different letter like l? Would sure make things easier!
(of course I COULD just edit manually those offending lines but 2x49+4x29 lines to be removed across LARGE files...Uhhuh. And this for simple objects. Not good. More preferably converter should do that thing automaticly).
Edit: And elsewhere. How on earth can one get double free or corruption error message when deleting non-NULL pointer?
Code:
object3d::~object3d() {
if(myFrames!=NULL) {
for(int i=0;i<frameCount;i++) {
if(myFrames!=NULL) {
printf("myFrames isn't NULL!\n");
}
if(myFrames[i].vertexTable != NULL) {
printf("vertex table isn't NULL!\n");
}
if(myFrames[i].vertexTable != NULL) delete[] myFrames[i].vertexTable;
if(myFrames[i].normalTable != NULL) delete[] myFrames[i].normalTable;
if(myFrames[i].normalIndexes != NULL) delete[] myFrames[i].normalIndexes;
}
if(myFrames!=NULL) delete[] myFrames;
if(myPolygons!=NULL) delete[] myPolygons;
if(uMapTable!=NULL) delete[] uMapTable;
if(vMapTable!=NULL) delete[] vMapTable;
}
}
Goes haywire on trying to delete vertexTable. myFrames is frame *myFrames; and frame is:
Code:
struct frame {
vertex *vertexTable;
normalVector *normalTable;
int *normalIndexes;
int normalCount;
};
(vertex is just struct with 3 float values).
Only one place in code where object3d classes gets destroyed(destructor of client which loops through vector containing these objects deleting them if not NULL) so there shouldn't be any rogue destructor calls as far as I can tell. And unless I'm mistaken those if clauses should prevent any attempt to delete NULL pointers.
Even more weird is that other section of code that works pretty much identically works...Go figure. Variable names change and location of functions change but that's it.
edit: Found post in forum which suggested typing in console before running:
export MALLOC_CHECK_=0
and sure enough no crash then. Okay so anything I can do codewise to prevent this? Or do I have to wrap executable into script to ensure that's run before running? What's causing this that above prevents it? Is it just hiding symptoms? What's going on here?
Bookmarks