2
#include <vector>

std::vector<int> v[1000];

int main()
{
    return 0;
}

I just used this code with Visual Studio 2019.

    Project1.exe!__CheckForDebuggerJustMyCode() Unknown
>   Project1.exe!std::exchange<std::_Container_proxy *,std::nullptr_t>(std::_Container_proxy * & _Val, void * && _New_val) Line 599 C++
    Project1.exe!std::vector<int,std::allocator<int>>::~vector<int,std::allocator<int>>() Line 676  C++
    Project1.exe!`eh vector destructor iterator'(void * ptr, unsigned __int64 size, unsigned __int64 count, void(*)(void *) destructor) C++
    Project1.exe!`dynamic atexit destructor for 'v''()  C++
    ucrtbased.dll!00007ffbdf8e48d7()    Unknown
    ucrtbased.dll!00007ffbdf8e42e5()    Unknown
    ucrtbased.dll!00007ffbdf8e441a()    Unknown
    ucrtbased.dll!00007ffbdf8e4a81()    Unknown
    ucrtbased.dll!00007ffbdf8e3c51()    Unknown
    ucrtbased.dll!00007ffbdf8e3afd()    Unknown
    ucrtbased.dll!00007ffbdf8e3b6a()    Unknown
    ucrtbased.dll!00007ffbdf8e3de4()    Unknown
    ucrtbased.dll!00007ffbdf8e4176()    Unknown
    Project1.exe!__scrt_common_main_seh() Line 297  C++
    Project1.exe!__scrt_common_main() Line 331  C++
    Project1.exe!mainCRTStartup() Line 17   C++
    kernel32.dll!00007ffc168c7034() Unknown
    ntdll.dll!00007ffc1829cec1()    Unknown

access violation on 0x00007FF6087210D2. Here is a call stack

Why this code crashes? I try to install another version of visual studio (2017), but it still crashes. I've also tried reinstall Window SDK, but it doesn't work.

What can be possible reason, and how to solve it?


Second code sample:

#include <stdio.h>
#include <vector>

int main()
{
    printf("before\n");
    std::vector<std::vector<int>> v(3000);
    printf("after\n");
    return 0;
}

The exception changes for every run. One of call stack for above code is:

    ConsoleApplication2.exe!std::vector<int,class std::allocator<int> >::_Getal(void)   Unknown
    ConsoleApplication2.exe!std::vector<int,std::allocator<int>>::vector<int,std::allocator<int>>() Line 446    C++
    ConsoleApplication2.exe!std::_Default_allocator_traits<std::allocator<std::vector<int,std::allocator<int>>>>::construct<std::vector<int,std::allocator<int>>>(std::allocator<std::vector<int,std::allocator<int>>> & __formal, std::vector<int,std::allocator<int>> * const _Ptr) Line 695  C++
    ConsoleApplication2.exe!std::_Uninitialized_backout_al<std::allocator<std::vector<int,std::allocator<int>>>>::_Emplace_back<>() Line 1509   C++
    ConsoleApplication2.exe!std::_Uninitialized_value_construct_n<std::allocator<std::vector<int,std::allocator<int>>>>(std::vector<int,std::allocator<int>> * _First, unsigned __int64 _Count, std::allocator<std::vector<int,std::allocator<int>>> & _Al) Line 1835   C++
    ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::_Ufill(std::vector<int,std::allocator<int>> * _Dest, const unsigned __int64 _Count, std::_Value_init_tag __formal) Line 1584    C++
    ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::_Construct_n_copies_of_ty<std::_Value_init_tag>(const unsigned __int64 _Count, const std::_Value_init_tag & _Val) Line 462  C++
    ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>(const unsigned __int64 _Count, const std::allocator<std::vector<int,std::allocator<int>>> & _Al) Line 473 C++
>   ConsoleApplication2.exe!main() Line 8   C++

+

this code also crashes

#include <vector>

int main()
{
    auto a = new std::vector<int>[3000];
    delete[] a;
    return 0;
}
#include <string>

int main()
{
    auto a = new std::string[3000];
    delete[] a;
    return 0;
}

So I doubt insufficient memory, however below code works well.

#include <vector>

int main()
{
    auto a = new int[10000000];
    delete[] a;
    return 0;
}

I've try to uninstall all visual studio and Window Kits in visual studio installer, and reinstalled them, however, it still occurs.

Liastre
  • 1,281
  • 11
  • 29
Gimun Eom
  • 411
  • 5
  • 17
  • 6
    Possibly not related to your error, but `std::vector v[1000];` is declaring an array of 1000 vectors. Did you mean `std::vector v(1000);`? – scohe001 Oct 22 '20 at 01:09
  • 1
    There's nothing wrong with the shown code, this is obviously some kind of an unknown installation or corruption problem with your compiler or runtime library. – Sam Varshavchik Oct 22 '20 at 01:10
  • 1
    I'm not having any luck reproducing this behaviour. – user4581301 Oct 22 '20 at 01:11
  • 1
    It looks like a crash on destruction, rather than construction - `dynamic atexit destructor for 'v''` - but still, it looks like it might be some sort of VS bug. – Ken Y-N Oct 22 '20 at 01:14
  • @scohe001 it's just to reproduce. if I use std::vector v[1000], it doesn't crash. However std::vector> v(1000) can reproduce it. – Gimun Eom Oct 22 '20 at 01:18
  • @Ken Y-N ```[code 2]``` this code sometimes crashed before 'after'. (sometimes after 'after'). – Gimun Eom Oct 22 '20 at 01:24
  • @Ken Y-N The exception changes for every run. One of call stack for above code is ```[callstack 2]``` – Gimun Eom Oct 22 '20 at 01:27
  • I guess runtime library is corrupted. However, I've tried to recover Visual Studio in Visual Studio Installer, but it still fails. How can I fix it? – Gimun Eom Oct 22 '20 at 01:31
  • @GimunEom Throw out your laptop and get a new one. Or uninstall Visual Studio completely and reinstall it. – Anonymous1847 Oct 22 '20 at 01:59
  • 1
    @GimunEom `std::vector> v(1000);` is incorrect code though, since 2nd dimension vectors must be initialized as well. Proper code would be `std::vector> v(3000, std::vector(3));` for example – Liastre Oct 24 '20 at 16:06
  • It works fine when I test all the code in VS2017 and VS2019. If you have reinstalled VS, I suggest that you could try to test it in another computer to troubleshoot the problem. – Barrnet Chou Oct 26 '20 at 07:02
  • @Liastre it is not incorrect. that constructor initialize their elements as empty vector by calling default constructor. – Gimun Eom Oct 27 '20 at 00:35
  • @GimunEom glad you've resolved your issue. Well it reminds me issue with multi dimensional vector initializing back then, when I've used VS2013. It was a compiler bug, not a standard mistake, cool that's not the case. – Liastre Oct 27 '20 at 11:28

1 Answers1

2

I testet your program in visual studio 2019 because this is what you are using.

#include <vector>

std::vector<int> v[1000];

int main()
{
    return 0;
}

It works just fine. But you know this already. I am using this in 64-bit mode. (which you have done also)

Because it crashed when you use "std::", I checked the DLL's which are loaded when using std and without. You should check the difference in DLL's. Without STD: enter image description here

With STD:

enter image description here

I am not sure if it really is a software problem. (because you mentioned you tested with visual studio 2017 and it did still crash) In that case, I would think it is a problem with your RAM. Maybe you can test your code on a different computer.

wpeeters
  • 138
  • 5
  • I've solved it. That was problem of ucrtbased.dll. it was not reinstalled when I reinstall when I reinstall visual studio and their components. (even if when I reinstall universial crt, it is not recovered) I've deleted and replace it. – Gimun Eom Oct 27 '20 at 00:38