Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in igraph. I want to create a graph from a text file(in each line there are the source vertex of the edge and target vertex of the edge) and then print it. but, it gives an error: "consoleApplication1.exe has triggered a breakpoint".this error happens while running the line "igraph_get_edgelist(&graph, &v, 0);".I did not set a breakpoint. the debugger sets it and the position it shows to me is a line in dbgheap.c file which is not a file made by me. after I click the "continue" button in the message box, this erroe occurs: "Debug Assertion Failed!
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c". why this error occurs?

igraph_vector_t v;
 igraph_empty(&graph, 7, 0);
 ifstream inputFile("sample.txt");
 string line;
 igraph_vector_init(&v, 0);
 while (getline(inputFile, line))
 {
     istringstream ss(line);
     int v1, v2;
     ss >>  v1 >> v2 ;
     VECTOR(v)[0]=v1; VECTOR(v)[1]=v2;
     igraph_add_edge(&graph, v1, v2);
 }


 /* Check result */
 igraph_get_edgelist(&graph, &v, 0);
 igraph_vector_sort(&v);
 print_vector(&v, stdout);


What I have tried:

i do not know the reason of it
Posted
Updated 2-Apr-17 21:39pm
v6

Quote:
t gives an error: "consoleApplication1.exe has triggered a breakpoint".

A breakpoint is not an error !
A breakpoint is related to the debugger, it is something you set at a position in your code in order to stop the program execution when it reach that position and switch to debugger mode.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
Comments
Member 11807654 2-Apr-17 14:09pm    
but, I did not set a breakpoint. the debugger sets it and the position it shows to me is a line in dbgheap.c file which is not a file made by me. after I click the "continue" button in the message box, this erroe occurs: "Debug Assertion Failed!
File: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c"
Patrice T 2-Apr-17 14:16pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Member 11807654 2-Apr-17 14:27pm    
ok, thanks
the breakpoint is firing on an assertion that's failing

determine what the assert is, why it's failing, and fix it in your code

i'd imagine you're corrupting the heap
 
Share this answer
 
You are getting an assertion in the heap handling. You can check the mentioned line by viewing the source of dbgheap.c (see at VC<version>\crt\src in your VisualStudio directory).

Such assertion usually indicates a heap corruption.

I have never used igraph but the error is obvious and verified when reading the igraph Reference Manual[^].

igraph_vector_init(&v, 0);
Quote:
This function constructs a vector of the given size and initializes each entry to 0.

VECTOR(v)[0]=v1
Quote:
The simplest way to access an element of a vector is to use the VECTOR macro. This macro can be used both for querying and setting igraph_vector_t elements.
...
Note that there are no range checks right now.

You are creating a vector of the size zero and then try to access elements. This will of course fail because no memory has been allocated on the heap and accessing elements uses probably a NULL pointer which is catched later by the heap checks.

You have to check first how many elements are in your input file and pass that number to igraph_vector_init() to allocate the required memory.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900