Vector Iterators Incompatible
Added by Pat Ivory about 10 years ago
Hey,
So when I run my application in a microsoft visual studio debug environment, i run into the exception described by the title of this post.
I have been unable to find much about this (on the Wt forum), other than the thread linked below
http://redmine.webtoolkit.eu/boards/2/topics/656
Accepting for a second that I have my compiler incorrectly configured, what settings do I require, if I am using Wt 3.3.4 RC2 pre-built binaries (and yes I have got the correct runtime version, or else the program wouldn't have loaded ;) )?
Replies (10)
RE: Vector Iterators Incompatible - Added by Wim Dumon about 10 years ago
Hello,
Can I deduce from your comment that all is working well in the Release configuration?
In debug, you need to link to wtd.lib, wthttpd.lib (notice the 'd' in the end of the library) instead of wt.lib, wthttp.lib etc. These libraries are compiled against the debug versions of the C runtime libraries.
Best regards,
Wim.
RE: Vector Iterators Incompatible - Added by Pat Ivory about 10 years ago
Unfortunately, that isn't a fair assessment.. oh and I should have mentioned that I am linking against the correct versions of Wt, and did a complete rebuild of the project and working directories to ensure that I am linking and loading the correct libs & binaries.
Neither the release nor the debug work correctly. Though it is a little difficult to determine if the issues seen in release and debug are the same.
I'm not exactly sure how I might be certain they are, can you suggest anything?
If you are interested in the problem, please see the attached call stack from which the error is thrown..
CallStack.xlsx (9.65 KB) CallStack.xlsx |
RE: Vector Iterators Incompatible - Added by Pat Ivory about 10 years ago
Hi Wim,
I can confirm after some more testing that the issue is only present when running the debug build.
Cheers,
Pat
RE: Vector Iterators Incompatible - Added by Anonymous about 10 years ago
And also this for _SCL_SECURE discussion:
http://redmine.webtoolkit.eu/boards/1/topics/1048
It would be useful to know your compiler version and a sinppet of the offending code. If you're getting a "Vector Iterators Incompatible" exception then it's probably not an _SCL_SECURE build issue as that would either be a weird crash or a link error depending on your compiler version. It's more likely that you are comparing iterators from different collections, such as is shown in this stack overflow post:
http://stackoverflow.com/questions/8421623/vector-iterators-incompatible
Also be aware that vector iterators become invalid if the vector reallocates its buffer, so any iterator created before you do, say, a push_back() may become invalid. This is especially true of the iterator returned by end(). Again on StackOVerflow:
http://stackoverflow.com/questions/15855634/why-am-i-getting-vector-iterators-incompatible
Chances are that you are misusing the STL in your code somewhere. If that's the case then you can thank Microsoft for the excellent iterator checking! I haven't looked at the call stack you posted, but the site that the exception is thrown from (make sure you set up your debugger to stop on exceptions being thrown) should pinpoint where you've gone wrong.
Cheers,
Dan
RE: Vector Iterators Incompatible - Added by Wim Dumon about 10 years ago
Hello,
The stack trace points to some Wt code. This is the place of where the invalid compare is happening according to the stack trace:
template<typename T>
inline bool erase(std::vector<T>& v, const T& value)
{
typename std::vector<T>::iterator i = std::find(v.begin(), v.end(), value);
if (i != v.end()) { // Offending line, #115
v.erase(i);
return true;
} else
return false;
}
I'm really confused about how this can happen (other than the reason I already specified, or as consequence of an ordinary memory error). Is this a Wt example you're trying to compile?
BR,
Wim.
RE: Vector Iterators Incompatible - Added by Pat Ivory about 10 years ago
Hey Wim, Dan,
Thanks for the feedback.
Firstly Wim - No it's not an example, it's part of an application that I am developing. At this stage it is rather messy and hard to isolate different sections of the code which interact with the web server, but this is what I am working on to pin point the problem.
Dan - Setup up is as follows
- I am using the pre-compiled 3.3.4 RC2 binaries of Wt, distributed with boost 1.56
- The application itself is compiled using MFC in a shared DLL (there is a desktop part of the application which provides console like function)
anyone, I had a sneaking suspicion that the problem was to do with client sessions timing out. In which case, I assumed that the destruction of the client object would be initiated, whilst in parallel, the server was trying to post updates to this client and causing my problem. But after the session timeout has elapsed, the object is not being destroyed.. What is the expected behaviour following a session timeout?
RE: Vector Iterators Incompatible - Added by Pat Ivory about 10 years ago
I think the problem has been found... Another thread was calling WSAStartup multiples times, along with WSACleanup.. AFAIK, this only needs to be called once per thread.. After fixing this, we don't seem to be having the same problem.. I'll leave the code running for a little while longer before I say this issue is fixed..
On another note, why does the creation of a WApplication instance throw an exception?
RE: Vector Iterators Incompatible - Added by Wim Dumon about 10 years ago
Normally WApplication does not throw an exception. What exception is thrown?
BR,
Wim.
RE: Vector Iterators Incompatible - Added by Pat Ivory about 10 years ago
Hi Wim,
Apologies for the delay.
Using the pre-built binaries for vc 10 for Wt 3.3.4 (stable release).
I compiled and ran the hello world example provided. Turning the debugger on to catch all the exceptions thrown, the attached call stack precedes the exception thrown during creation of the client application.
The exception does not create a crash, so it could potentially be a Visual Studio debugger problem? (Though I have also tested in vc 13, and obtain the same problem).
BR,
Pat
RE: Vector Iterators Incompatible - Added by Wim Dumon about 10 years ago
Hello Pat,
I tested the prebuilt msvs 2013 64bit build with MSVS2013 update 4. When I turn on all exceptions, I see a callstack that resembles yours, i.e. the stack is:
KernelBase.dll!RaiseException() Unknown
[External Code]
> wtd.dll!Wt::WEnvironment::getCookie(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & cookieName) Line 435 C++
wtd.dll!Wt::WebSession::handleRequest(Wt::WebSession::Handler & handler) Line 1388 C++
wtd.dll!Wt::WebController::handleRequest(Wt::WebRequest * request) Line 713 C++
That is an expected exception, and is caught in WebSession.C. Note that if you enable 'break on exception', the debugger will break when an exception is thrown, irrespective of the fact if it was expected or not, so your program may break on properly handled exceptions.
I don't see however the incompatible iterators exception. Do you get it on MSVS 2013?
Wim.