I had asked this question a while back where the following declaration results in a run time crash on W7 machine.
std::vector<Eigen::MatrixXd> inv_K_mat2(42, Eigen::MatrixXd::Zero(4, 5));
However now I am seeing this on a Win10 machine also and wondering if I can get some help figuring this out. Since Win10 is a supported platform I need to somehow address this issue. Running through the debugger I see the application crashing exactly at the above line. Other declarations such as
Eigen::MatrixXd BMat(3,10);
are working. I can't determine why the above declaration is failing on some machine architecture. May be it is due to the mixing of stl containers with Eigen or missing run time libraries? Is there another way to specify the above declaration. Any help to fix this problem is very much appreciated
Related
I was writing some simple C++ code using DevC++ when this error came up:
I have no clue as to why I am getting this upon initialising a vector array (a graph adjacency list).
I couldn't co much to solve this problem since I am not an expert in c++ compilers. I tried reinstalling the program but that didn't help at all.
My compiler is TDM-GCC and in the compiler options I added "-std=c++11", which is executed when calling the compiler.
This line
std::vector<int> adj[NK];
defines an array of 100 million std::vector objects, along with a static initializer to create all of them.
Did you mean to create a single vector of size 100M?
std::vector<int> adj(NK);
Despite the fact that I made a mistake in the code, it still compiled successfully after a very simple fix. The compiler used to be a 64-bit Release version. I changed the field to the 32-bit Release and the problem disappeared, despite the ridiculous amount of memory my program had needed.
Please note that your mileage may vary and this solution might have some side effects I am not aware of. However, this worked just fine for me and it seems that all my other c++ files compile without any errors.
Working Fortran compilers sometimes generate invalid Win32 .exe files
Hello everybody,
several working Fortran compilers seem to have a strange behavior in certain situations. I have tried to compile and run Prof. John Denton's programs which can be found here:
https://www.dropbox.com/sh/8i0jyxzjb57q4j4/AABD9GQ1MUFwUm5hMWFylucva?dl=0
The different versions of the programs Meangen und Stagen could be compiled and worked fine. The last program named Multall also has several different versions. As before, the appropriate source codes could be compiled without any problems. But: as I tried to run the resulting .exe files, I got a very strange error message saying Multall's .exe would NOT be a valid Win32 executable.
I used four different Fortran compilers (g77, Cygwin, Mingw, FTN95) on Windows XP and Windows 8, always with the same result. I made several tests, and it seems to me the reason of the strange error message is the huge amount of source code Multall consists of. There are much more than 16000 lines of code, so maybe the memory being allocated by default by the compiler for the code segment is too small and an overflow occurs.
I tried several command line options of the g77 compiler in order to increase the code segment's amount of memory, but none worked. Can anybody tell me which of the g77's command line options make the huge program Multall's .exe work? Or maybe I am wrong, and the strange error message has nothing to do with the code segment? Who can help me?
Thanks a lot, I highly appreciate your help
Indeed, the problem is not the program size but the stack size. This is due to the large common blocks. As a test you could reduce JD in commall-open-18.3 to 1000 and you will notice that the problem is solved.
You could check whether the arrays are not oversized and adjust some parameters.
I tried reducing common blocks - without any effect - then I tried on another computer and there the compilation went fine and the code runs - I am guessing it is some sort of screw-up of the libraries - maybe because I made a messy (first) installation where I didn't really know what I wass doing - but I really don't know.
The C++ projects I wrote and run without any problems on Ubuntu return the exception "vector subscript out of range" when I run them on windows. I use Windows 7 and Visual C++ 2008 Express.
I hope that makes sense to someone.
The version of the STL shipped by Microsoft comes with checked iterators, which when run in debug mode ensure that your vector indices are in range. No such checking is done in GCC by default.
Your code almost certainly contains undefined behavior. In such a case, an implementation is free to do almost anything it wants. It appears that gcc has basically ignored the problem, so it wasn't apparent. VC++ has built enough self-monitoring into your code to find the problem and tell you about it.
The next step is pretty much up to you: find the problem in your code and fix it. Unfortunately since you haven't posted any of the code, it's essentially impossible to give much more detailed advice about what you should do or how to do it. About the only hint I can think of is that the debugger in VC++ does have a nice stack trace feature, so if you run the code under the debugger and it fails, it's pretty easy to walk back up the stack to find the code that called the function (that called the function, etc.) where the problem was detected.
I have a Visual Studio 2008 solution which consists of some projects and uses dll's with theirs' headers. In the debug version it (the solution) works really well. And in release version it compiles successfully, but on executing some functions which are defined in a dll file it fails.
As I said, the solution works fine in debug mode, and options set properly. Tried turning off
optimization, turned on debugging information, it didn't help. What can be the cause of the problem?
I have seen this happen many times before. In almost every single case the problem was found to be an out-of-bounds error when writing to an array or other data structure. In other cases, an uninitialized variable was being used.
You have a bug in your code. That is certain. When you build under Debug settings, the compiler does a whole lot of stuff for you that masks certain types of problems. The compiler will write code that zero-initializes some stuff, masking uninitialized variable problems.
First thing I wold try is cranking up the warning levels to their highest settings. You should be doing this all the time anyways. This will very often reveal the problem. Just be sure to fix the problems the compiler tells you about. Don't mask them with #pragmas or chintzy casts. Next step through your code to isolate the problem. This can be difficult and time consuming, but there's a silver lining. Whatever the problem is, the likelyhood of you repeating that mistake is inversely proportional to how long and how hard it is to identify and fix the bug. :)
I am in big big trouble. Please help.
I have created a game for my client.
It works fine when I run it from the Visual Studio 2008( in both release and debug configuration).
But when I run its stand alone exe (or making setup project) it does not work perfectly fine.
It works but it does not work completely fine,and the problem is consistent(It shows the same problem every time, when I compile and run stand alone exe).
I had this problem in the past too but luckily I solved it.The way that problem was solved is very unusual:-
Every thing was working perfectly fine and then I made some modifications in the code.The application started showing the same unusual behavior as described above.Then i started rolling back the modifications in the code one by one.
The game started working perfectly fine when i removed a particular variable from a class and it uses.Then I checked all the C++ rules and every thing but found no issue in my implementation.Even every thing was working fine when i run from the Visual Studio.
But I needed that variable and its uses in the game for some functionality of the game.So, that time I declared the variable in PUBLIC (previously it was a protected variable) and every thing worked perfectly fine.
I am very surprised to see this unusual behavior, whenever i declare the variable as PROTECTED there is problem but if I copy and paste in Public the problem is solved.(The variable is only being used in the Class where it is declared so there should not be any problem).
Please Help me I am again getting this unusual problem and not getting any solution this time.
Please tell me what may cause this problem.
Thanks
Tarun
If it happens outside the debugger, but not inside the debugger, you may be able to reproduce it using the _NO_DEBUG_HEAP environment variable, as described here (amongst other places): Link
Setting this variable should make the program running under the debugger behave more like the program running outside the debugger.
You can set environment variables in Visual Studio, so they affect only the debugged process: How do I set specific environment variables when debugging in Visual Studio?
Changing the visibility of member variables can potentially change the layout of the class, since C++ only defines an ordering within visibility sections, not between them. Perhaps your change is breaking some code that isn't recompiled by your project.
I solved this problem. It was really very very hard to find the solution. I am writing here how to track this kind of bugs.
Some steps you should try first:-
1) Dont ignore compiler warnings. Remove all types of warnings.
2) Program to write the states of the variable in a file in near the critical portion of your program where you are in doubt that is causing error.
Write the states on each step.
Examin the Variable, you may find some un initialize variables or improper type cast or comarison.
Conclusion:
1) Avoid any coparison (equal to comparison)with floating point values.
2) If you are making time based comparison, make sure you comapre that care fully.
3) Do not this Microsoft People are god.