Dear forum,
I recently converted my C++ projects from Visual Studio 2003 to Visual Studio 2005. In 2003 everything worked fine, but now I get the following errors when using a .lib in an executable program.
* When .lib is in debug mode and exe also in debug I get the following error:
"vector subscript out of range", .... \VC8\include\vector, line 756
Although this might seem strange to all of you I am 100% sure that my vector is NOT going out of range there!!
* When .lib is in debug mode and exe in release I get the following error:
"Runtime library has detected a fatal error"
* When .lib is in release mode and exe in debug I get:
"Unhandled exception in msvcr80d.dll"
* When .lib is in release mode and exe in debug mode:
IT WORKS FINE!
Can anyone give me a hint on what is happening here
edb

vector subscript out of range in debug
karls123
When upgrading to Visual Studio 2005, it is important to make sure that NO trace of VS2003 can make its way into your VS2005 project, neither in your lib nor your exe.
What I tend to do is completely clean out my source tree (every obj, every lib, every sbr, every cpp every h.) and download one afresh from the SourceSafe repository. Then I do a full rebuild of the solution.
I'd like to see the source code for myself before I make this conclusion. What do the local variables say in the debugger Reminder: the valid range for a vector index/iterator goes from 0 to size()-1. For an empty (zero sized) vector, no index or iterator is valid.
This is a different problem. Note that you CANNOT mix release libs with debug exes (or vice versa). The only supported scenarios are that EVERYTHING is debug or EVERYTHING is release. Mixing a debug lib with a release exe is an unsupported scenario, and crashes and unhandled exceptions are just some of the symptoms you'll get.
The same goes for mixing libs from different compilers and different versions of the same compiler.
BryanHood
I kind of have the same problem. It looks like VS2005 has more safty features than VS6 and VS2003. Especially, when we use multi-threaded model, we do not know what exact the code executed. So for example, we want to acces the last element in the vector and then erase it. But what happens is that the vector may erase the element before we access it since we have multi-threaded. Add lock or mutex might solve the problem. Hopefully, it helps.
VIGILJO
Scott Sullivan
Hi,
I cannot send the entire code, but here is some simplified test code to specify the problem:
The error pops-up here on the push_back(). I get the same error when I do an index call on a sortlike vector, which is in another lib (notice the & in the return type for GetVector... maybe this is the problem, I had some similar problems with calling eg. c_str() on a function which returns by ref..., this was in VS2003, but it works fine on linux):
The other was indead a typo, sorry. I know that for some reason it is not allowed to mix debug and release libs/exes, but I always wonder why. What if you want to use a precompiled .lib file which was compiled in release mode, for which you do not have the code and cannot generate a debug .lib.... How can you debug the program that uses this lib Never had problems with that before (but I must add, I worked under Linux for a long time...)
Rainman86
With these classes:
testlib.h:
s_muneer
#include "fire.h"
vector < fire > MYFIRE;
In main I have this function
for(unsigned int i = 0 ; i < MYFIRE.size(); ++i)
{
MYFIRE
if(MYFIRE
{
for(int j = i; j < MYFIRE.size(); ++j)
{
MYFIRE[MYFIRE.size()] = MYFIRE[j];///////////error here
}
MYFIRE.pop_back();///////////error here
}
}
And this is where I put things into the vector array
case 32: //enter
MYFIRE.push_back(fire());
MYUSERSHIP.userfire(MYFIRE[MYFIRE.size()-1],userVel);
break;
Can anyone help me come across a way to fix this
heldchen
Hi !!
Osha, could you help me I have the same problem ::
"vector subscript out of range", .... \VC8\include\vector, line 756
and ("Strandard C++ library Out of Range",0) line 757
Cheers.
Nabyl.