i have made a game using DirectX, and it runs fine. Until it shuts down.
then do i get the error:
"Unhandled exception at 0x6af7ad54 (msvcp100d.dll) in NewStickFigWars.exe: 0xC0000005: Access violation writing location 0xfeeefeee."
i know that 0xfeeefeee is freed memory, and that would suggest that i am deleting memory twice, but I didn't call a deconstructor or something simular.
my game has lots of classes,and it has vectors filled with pointers to classes from a array.
Are you sure you haven't called any destructor? This looks like one of those issues I'm afraid, the ones that have you commenting out all of your delete commands and destructor calls one by one and recompiling or going through the code with a debugger. Sorry.
The reason I asked about smart pointers is that if their destructors are fired -- to release a COM object -- after CoUnititialize has been called, you can see this kind of problems.
I always make sure that all my COM objects are released before calling CoUnititialize.
Can you see the stack trace which led to the exception?
I did not delete anything,but something else might do that.
here is the whole stack trace:
NewStickFigWars.exe!std::vector<int,std::allocator<int> >::_Tidy() Line 1304 + 0xb bytes C++
NewStickFigWars.exe!std::vector<int,std::allocator<int> >::~vector<int,std::allocator<int> >() Line 706 C++
NewStickFigWars.exe!Model::~Model() Line 194 + 0xb bytes C++
NewStickFigWars.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 935 + 0x18f bytes C++
NewStickFigWars.exe!__tmainCRTStartup() Line 547 + 0x2c bytes C
NewStickFigWars.exe!WinMainCRTStartup() Line 371 C
"Model" is the name of a class in my game, that class stores pointers to DirectX10 objects, and it has a empty deconstructor. that is a class wich i have in a vector.
EDIT:
i have found that one of the pointers in the Model class is invalid. the pointer has the value 0x00000004.
this only happened to one of the pointers in the Model class.(a pointer to a vertex buffer), however, all the Model classes in the vector do have this problem, and they have that problem the whole program, but does my program work
I don't know if this is relevant, but my program uses multiple threads
Your stack trace says that an instance of the Model is being destroyed during a call to WinMain. Or possibly as the call returns. Is this class a global?
In an earlier post you said you were not calling delete. DId I understand correctly?
Also, are you using #import to include the Direct3D or #include?
You can set a breakpoint which is triggered when the data stored at a memory address changes.
If you you which variable has been prematurely deleted and set to 0xfeeefeee, you could set a data breakpoint on it to determine where it's first deleted.
You could use the same technique (data breakpoint) to check out the pointer with value 4.
Regarding threads: are they also using the model directly? Do you stop the thread to quit before you exit WinMain?
And: I do think it would better if you could get your global object to dismantle itself before WinMain is exited. I've just had a look at the Windows SDK's Direct3D sample, and they are following the same approach (it is using DirectX 9, though). They call their Cleanup() function, to release all the interfaces, just before WinMain exits.
i have used the data breakpoints, and i think the error is in a member of the model class, wich is a vector with integers. i had put a data breakpoint at the adres of a member vector(the vector with the integers) of the last model in the vector, and direct after that breakpoint was hit, i got the error.
i guess that the integers-vector member is double destroyed. So, how do i stop this?
the second thread of my program(that thread is created by a multimedia timer) stops before WinMain ends. The models are only used directly in the beginning of the program, after that, the program uses pointers to them. The pointers to the models are stored in a vector.
the deconstructors used to have that code that you have in the Cleanup() function, but i removed that because i thought it was removed twice.
but i will give it a try to clean everything up before WinMain ends.
Well, your original post was about an access violation trying to write to feeefeee, so one possibility was to stop that write if possible (but I don't/didn't have enough info to know if that's possible, hence question about the call stack, étc)
And you were worried about double destroying the vector, so there was a tiny chance that it it had been newed. Then there might have been in the pointer guard logic. But as it is just a regular vector, that's probably irrelevant.
As it stands, the only way the int vector destructor would be called twice is if the model was destroyed twice. So it looks like it's probably a memory trampling issues.
Can you see what's setting the pointer value to 4 ???