0

I have developed windows application using VC++ which uses vector and queue (STL components). while running the application, I am getting error as "application.exe has triggered a breakpoint."

Adding call stack for more clarity.

ntdll.dll!RtlReportCriticalFailure ()   Unknown
ntdll.dll!RtlpHeapHandleError ()    Unknown
ntdll.dll!RtlpHpHeapHandleError ()  Unknown
ntdll.dll!RtlpLogHeapFailure () Unknown
ntdll.dll!RtlFreeHeap() Unknown
ucrtbased.dll!_free_base(void * block) Line 105 C++
ucrtbased.dll!free_dbg_nolock(void * const block, const int block_use) Line 1003    C++
ucrtbased.dll!_free_dbg(void * block, int block_use) Line 1030  C++
UnicastMulticastApp.exe!operator delete(void * block) Line 38   C++
UnicastMulticastApp.exe!operator delete(void * block, unsigned __int64 __formal) Line 32    C++
UnicastMulticastApp.exe!std::_Deallocate<16,0>(void * _Ptr, unsigned __int64 _Bytes) Line 221   C++
UnicastMulticastApp.exe!std::allocator<int *>::deallocate(int * * const _Ptr, const unsigned __int64 _Count) Line 804   C++
UnicastMulticastApp.exe!std::deque<int,std::allocator<int>>::_Tidy() Line 1483  C++
UnicastMulticastApp.exe!std::deque<int,std::allocator<int>>::~deque<int,std::allocator<int>>() Line 870 C++
UnicastMulticastApp.exe!bfs(std::vector<int,std::allocator<int>> * adj, std::vector<int,std::allocator<int>> * parent, int n, int start) Line 1540  C++
UnicastMulticastApp.exe!print_paths(std::vector<int,std::allocator<int>> * adj, int n, int start, int end) Line 1455    C++
int bfs(vector<int> adj[], vector<int> parent[], int n, int start)
{
    // dist will contain shortest distance 
    // from start to every other vertex 
    vector<int> dist(n, INT_MAX);
    queue<int> q;
    // Insert source vertex in queue and make 
    // its parent -1 and distance 0 
    q.push(start);
    parent[start] = { -1 };
    dist[start] = 0;
    // Untill Queue is empty 
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : adj[u]) {
            if (dist[v] > dist[u] + metricData[u][v]) {
                // A shorter distance is found 
                // So erase all the previous parents 
                // and insert new parent u in parent[v] 
                dist[v] = dist[u] + metricData[u][v];
                q.push(v);
                parent[v].clear();
                parent[v].push_back(u);
            }
            else if (dist[v] == dist[u] + metricData[u][v]) {
                // Another candidate parent for 
                // shortes path found 
                parent[v].push_back(u);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        metricData[start][i] = dist[i];
    }
    return 0;
}
Sham Kota
  • 1
  • 3
  • That message has a `Retry` button that gets you in the Debugger to the line that caused it. Go to the `Call Stack` window and see where it is called from. – Vlad Feinstein Sep 30 '20 at 17:25
  • 1
    That indicates an error in your code. Nobody here can guess what/where since you did not post that code. – dxiv Sep 30 '20 at 17:27
  • @VladFeinstein Retry button is not there, when checked error on function return occurred on call to ~deque() (~vector() in some cases.) – Sham Kota Oct 01 '20 at 07:08
  • Are you running your app in Debugger? From Visual Studio (F5)? Where do you see that error? When you call `print_paths(std::vector * adj, int n, int start, int end) ` - are `n`, `start` and `end` valid? – Vlad Feinstein Oct 01 '20 at 16:21
  • @VladFeinstein running app in debugger. yes, n, start and end are valid. I am getting error when returning from function bfs(std::vector> * adj, std::vector> * parent, int n, int start). when we return from any function, related destructor gets called automatically same in my case also, but in the call to destructor only I am getting error. Unable to understand why is the error. – Sham Kota Oct 07 '20 at 05:59
  • Could you show your code for `bfs` function? – Vlad Feinstein Oct 07 '20 at 15:55
  • @VladFeinstein i have referred code from https://www.geeksforgeeks.org/print-all-shortest-paths-between-given-source-and-destination-in-an-undirected-graph/?ref=rp with slight modification to code as per my requirement, but didn't change core logic of program and components of STL like queue and vector. – Sham Kota Oct 08 '20 at 10:54
  • @ShamKota the stack trace indicates (I believe) that the `queue` in your `bfs` is corrupted; the code on `geeks for geeks` looks OK. How sure are you that your "slight modification to code" didn't do that? – Vlad Feinstein Oct 08 '20 at 15:37
  • @VladFeinstein As I have not modified any code which operates on queue and vector, as code on geeksforgeeks considers edges of unit 1 in my case edges of unit is different. I have updated my question with code of bfs I am using. – Sham Kota Oct 09 '20 at 08:05
  • Where and how is `metricData` defined? You tagged your question with `visual-c++`, but it doesn't support variable length arrays that are used in referenced source; could you show how this `bfs` is called and the definition of that call parameters? – Vlad Feinstein Oct 09 '20 at 16:26
  • One more question: you run a Debug build under debugger, right? I thought it would break on out-of-bound access to your containers. Assuming that the memory of your queue is corrupted (what else could it be?), the first suspect is `vector dist`, declared right next to it. Can you make sure that `v` is valid here: `dist[v] = dist[u] + metricData[u][v];` – Vlad Feinstein Oct 09 '20 at 16:58

1 Answers1

1

That means, You program most probably has some errors in code. Check this answer as example: C++ Console Application1.exe has triggered a breakpoint You should check error log and look for specific line, which is referenced for exception trigger.

Arnis Juraga
  • 1,027
  • 14
  • 31