dimitris93
dimitris93

Reputation: 4273

Clion error while running c++ project

I have a project in C++ which I made myself and I am experiencing a strange error. About 50% of the times I run the project I get an error

Process finished with exit code -1073741819 (0xC0000005)

I have no idea why this happens. I am simply running a Dijkstra algorithm which I made myself and printing a couple of lines to the console. The data never change and I am only using a few bytes of memory. I don't understand why does the project manage to run sometimes, and sometimes gives me an error.

Upvotes: 0

Views: 6304

Answers (1)

Michael Burr
Michael Burr

Reputation: 340436

Your graph can have up to 9 verticies:

Graph *G = new Graph(9);

I assume that this means that any particular vertex can have a value from 0 to 8 since the code seems to use the vertex as an index into various vectors.

However, when you create the previousVertex vector in Dijkstra::Dijkstra(Graph *G, int s), you give it one less element than the number of vertices for some reason:

previousVertex = vector<int>(V - 1); // V is the number of vertices in G
                                     //   which is 9 in your example project
                                     //   so it will have 8 elements and
                                     //   can be indexed with 0-7

But you index it with various elements vertex value later:

previousVertex[v] = u; // I believe that `v` can have the value 8 at times

I think you may be going past the end of the previousVertex vector. I don't know why you're having trouble catching this in a debugger if it crashes 50% of the time.

Upvotes: 2

Related Questions