C++11 Segmentation Fault with for loop that works previously [on hold]











up vote
-7
down vote

favorite
1












I'm programming some C++ code to manipulate a PPM formatted image.
I'm a at a point where I get a segmentation fault over a vector<vector<vector<int>>>
This code works to print out the content of Frequency by iterating:



for(size_t i = 0; i < InfoSup.nbL-2; i++){
for(size_t j = 0; j < InfoSup.nbC-2;j++){
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << Frequency[i][j][k] << " ";
}
cout << " ";
}
cout << endl;
}


However, in a another function called like that:



SelectHighest_and_Fill(Displayfrequency(ListeCLF,Header,InfoSup),Header, InfoSup);


Where Select Highest_and_fill is the function in which I get the error, together with Displayfrquency, they are prototyped as such:



vector<vector<vector<int>>> Displayfrequency(vector<vector<int>> ListeCLF,header Header, infoSup InfoSup);


vector<vector<int>> SelectHighest_and_Fill(vector<vector<vector<int>>> Frequency, header Header, infoSup InfoSup);


Now the fun part, the error, I get it in that loop:



int max=0;
int indice_max=0;
int tempVal;
for(size_t i = 0; i < InfoSup.nbL-2; i++){
cout << "I: "<< i << " ";
for(size_t j = 0; j < InfoSup.nbC-2;j++){
cout <<"J: "<< j<< " ";
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << "k "<< k << " ";
tempVal=Frequency[i][j][k];
if (tempVal>max) {
tempVal=max;
indice_max=k;
}
}
}
}
}


Exactly at that piece of code : Frequency[i][j][k]
The IDE then points me to that part of stl_vector.h error



It seems like I'm trying to access data that is not defined, or does not exist, but I iterated over the whole Frequency triple vector with no problem, and iterating it with the exact same loop does not work.



Is there a way to fix this ?



Tank you very much :)










share|improve this question















put on hold as off-topic by gsamaras, Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    Without an Minimal, Complete, and Verifiable example this is going to be very hard to help you with. What happens between the loops, for example? Also please read about how to ask good questions, as well as this question checklist
    – Some programmer dude
    yesterday






  • 1




    You did not give a mcve. How can we be sure that the 3d vector or the bounds does not change between the print loop and the later loop?
    – user202729
    yesterday






  • 3




    Debug, check the bounds.
    – Matthieu Brucher
    yesterday










  • Anyway, try using stackoverflow.com/questions/16620222/… .
    – user202729
    yesterday















up vote
-7
down vote

favorite
1












I'm programming some C++ code to manipulate a PPM formatted image.
I'm a at a point where I get a segmentation fault over a vector<vector<vector<int>>>
This code works to print out the content of Frequency by iterating:



for(size_t i = 0; i < InfoSup.nbL-2; i++){
for(size_t j = 0; j < InfoSup.nbC-2;j++){
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << Frequency[i][j][k] << " ";
}
cout << " ";
}
cout << endl;
}


However, in a another function called like that:



SelectHighest_and_Fill(Displayfrequency(ListeCLF,Header,InfoSup),Header, InfoSup);


Where Select Highest_and_fill is the function in which I get the error, together with Displayfrquency, they are prototyped as such:



vector<vector<vector<int>>> Displayfrequency(vector<vector<int>> ListeCLF,header Header, infoSup InfoSup);


vector<vector<int>> SelectHighest_and_Fill(vector<vector<vector<int>>> Frequency, header Header, infoSup InfoSup);


Now the fun part, the error, I get it in that loop:



int max=0;
int indice_max=0;
int tempVal;
for(size_t i = 0; i < InfoSup.nbL-2; i++){
cout << "I: "<< i << " ";
for(size_t j = 0; j < InfoSup.nbC-2;j++){
cout <<"J: "<< j<< " ";
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << "k "<< k << " ";
tempVal=Frequency[i][j][k];
if (tempVal>max) {
tempVal=max;
indice_max=k;
}
}
}
}
}


Exactly at that piece of code : Frequency[i][j][k]
The IDE then points me to that part of stl_vector.h error



It seems like I'm trying to access data that is not defined, or does not exist, but I iterated over the whole Frequency triple vector with no problem, and iterating it with the exact same loop does not work.



Is there a way to fix this ?



Tank you very much :)










share|improve this question















put on hold as off-topic by gsamaras, Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    Without an Minimal, Complete, and Verifiable example this is going to be very hard to help you with. What happens between the loops, for example? Also please read about how to ask good questions, as well as this question checklist
    – Some programmer dude
    yesterday






  • 1




    You did not give a mcve. How can we be sure that the 3d vector or the bounds does not change between the print loop and the later loop?
    – user202729
    yesterday






  • 3




    Debug, check the bounds.
    – Matthieu Brucher
    yesterday










  • Anyway, try using stackoverflow.com/questions/16620222/… .
    – user202729
    yesterday













up vote
-7
down vote

favorite
1









up vote
-7
down vote

favorite
1






1





I'm programming some C++ code to manipulate a PPM formatted image.
I'm a at a point where I get a segmentation fault over a vector<vector<vector<int>>>
This code works to print out the content of Frequency by iterating:



for(size_t i = 0; i < InfoSup.nbL-2; i++){
for(size_t j = 0; j < InfoSup.nbC-2;j++){
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << Frequency[i][j][k] << " ";
}
cout << " ";
}
cout << endl;
}


However, in a another function called like that:



SelectHighest_and_Fill(Displayfrequency(ListeCLF,Header,InfoSup),Header, InfoSup);


Where Select Highest_and_fill is the function in which I get the error, together with Displayfrquency, they are prototyped as such:



vector<vector<vector<int>>> Displayfrequency(vector<vector<int>> ListeCLF,header Header, infoSup InfoSup);


vector<vector<int>> SelectHighest_and_Fill(vector<vector<vector<int>>> Frequency, header Header, infoSup InfoSup);


Now the fun part, the error, I get it in that loop:



int max=0;
int indice_max=0;
int tempVal;
for(size_t i = 0; i < InfoSup.nbL-2; i++){
cout << "I: "<< i << " ";
for(size_t j = 0; j < InfoSup.nbC-2;j++){
cout <<"J: "<< j<< " ";
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << "k "<< k << " ";
tempVal=Frequency[i][j][k];
if (tempVal>max) {
tempVal=max;
indice_max=k;
}
}
}
}
}


Exactly at that piece of code : Frequency[i][j][k]
The IDE then points me to that part of stl_vector.h error



It seems like I'm trying to access data that is not defined, or does not exist, but I iterated over the whole Frequency triple vector with no problem, and iterating it with the exact same loop does not work.



Is there a way to fix this ?



Tank you very much :)










share|improve this question















I'm programming some C++ code to manipulate a PPM formatted image.
I'm a at a point where I get a segmentation fault over a vector<vector<vector<int>>>
This code works to print out the content of Frequency by iterating:



for(size_t i = 0; i < InfoSup.nbL-2; i++){
for(size_t j = 0; j < InfoSup.nbC-2;j++){
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << Frequency[i][j][k] << " ";
}
cout << " ";
}
cout << endl;
}


However, in a another function called like that:



SelectHighest_and_Fill(Displayfrequency(ListeCLF,Header,InfoSup),Header, InfoSup);


Where Select Highest_and_fill is the function in which I get the error, together with Displayfrquency, they are prototyped as such:



vector<vector<vector<int>>> Displayfrequency(vector<vector<int>> ListeCLF,header Header, infoSup InfoSup);


vector<vector<int>> SelectHighest_and_Fill(vector<vector<vector<int>>> Frequency, header Header, infoSup InfoSup);


Now the fun part, the error, I get it in that loop:



int max=0;
int indice_max=0;
int tempVal;
for(size_t i = 0; i < InfoSup.nbL-2; i++){
cout << "I: "<< i << " ";
for(size_t j = 0; j < InfoSup.nbC-2;j++){
cout <<"J: "<< j<< " ";
for(size_t k = 0; k < Header.ListeSeuils.size()-1; k++){
cout << "k "<< k << " ";
tempVal=Frequency[i][j][k];
if (tempVal>max) {
tempVal=max;
indice_max=k;
}
}
}
}
}


Exactly at that piece of code : Frequency[i][j][k]
The IDE then points me to that part of stl_vector.h error



It seems like I'm trying to access data that is not defined, or does not exist, but I iterated over the whole Frequency triple vector with no problem, and iterating it with the exact same loop does not work.



Is there a way to fix this ?



Tank you very much :)







c++ vector segmentation-fault






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday









ChrisF

114k23215290




114k23215290










asked yesterday









Falanpin

14




14




put on hold as off-topic by gsamaras, Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by gsamaras, Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Owen Pauling, πάντα ῥεῖ, Max Vollmer, Toby Speight

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Without an Minimal, Complete, and Verifiable example this is going to be very hard to help you with. What happens between the loops, for example? Also please read about how to ask good questions, as well as this question checklist
    – Some programmer dude
    yesterday






  • 1




    You did not give a mcve. How can we be sure that the 3d vector or the bounds does not change between the print loop and the later loop?
    – user202729
    yesterday






  • 3




    Debug, check the bounds.
    – Matthieu Brucher
    yesterday










  • Anyway, try using stackoverflow.com/questions/16620222/… .
    – user202729
    yesterday














  • 2




    Without an Minimal, Complete, and Verifiable example this is going to be very hard to help you with. What happens between the loops, for example? Also please read about how to ask good questions, as well as this question checklist
    – Some programmer dude
    yesterday






  • 1




    You did not give a mcve. How can we be sure that the 3d vector or the bounds does not change between the print loop and the later loop?
    – user202729
    yesterday






  • 3




    Debug, check the bounds.
    – Matthieu Brucher
    yesterday










  • Anyway, try using stackoverflow.com/questions/16620222/… .
    – user202729
    yesterday








2




2




Without an Minimal, Complete, and Verifiable example this is going to be very hard to help you with. What happens between the loops, for example? Also please read about how to ask good questions, as well as this question checklist
– Some programmer dude
yesterday




Without an Minimal, Complete, and Verifiable example this is going to be very hard to help you with. What happens between the loops, for example? Also please read about how to ask good questions, as well as this question checklist
– Some programmer dude
yesterday




1




1




You did not give a mcve. How can we be sure that the 3d vector or the bounds does not change between the print loop and the later loop?
– user202729
yesterday




You did not give a mcve. How can we be sure that the 3d vector or the bounds does not change between the print loop and the later loop?
– user202729
yesterday




3




3




Debug, check the bounds.
– Matthieu Brucher
yesterday




Debug, check the bounds.
– Matthieu Brucher
yesterday












Anyway, try using stackoverflow.com/questions/16620222/… .
– user202729
yesterday




Anyway, try using stackoverflow.com/questions/16620222/… .
– user202729
yesterday












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Run this code in debugger and check the size of your Frequency matrix. You are probably out of bounds in at least one of the parameters (i,j,k).






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Run this code in debugger and check the size of your Frequency matrix. You are probably out of bounds in at least one of the parameters (i,j,k).






    share|improve this answer

























      up vote
      0
      down vote













      Run this code in debugger and check the size of your Frequency matrix. You are probably out of bounds in at least one of the parameters (i,j,k).






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Run this code in debugger and check the size of your Frequency matrix. You are probably out of bounds in at least one of the parameters (i,j,k).






        share|improve this answer












        Run this code in debugger and check the size of your Frequency matrix. You are probably out of bounds in at least one of the parameters (i,j,k).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        uceumern

        44139




        44139















            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules