0

Apologies if this is a little vague, but I really don't know what's happening.

Since I've added some file reading functionality to a simulation program it has started triggering breakpoints in various different parts of the code. Sometimes within the 'new' function, sometimes when it tries to open a pipe for gnuplot commands, and sometimes just at the end of the program.

Because none of this was happening before, and after a bit of debugging, I think that the cause is something to do with the combination of the file reading and dynamic memory allocation. But beyond that I really don't know what is causing this, especially because it only happens occasionally. Can anyone offer any advice on this?

EDIT: It's been pointed out that this isn't actually a breakpoint, but a visual studio error indicating a problem with the heap allocation. Similar to This other question, so I may just have to go away and check all of my dynamic memory pointers. This being said, I would still appreciate it if anyone has any advice they could offer about this.

Below are code snippets of the functions that I've added.

string input = "C:/Users/ME/Documents/Data/Cilium/Raw/size.dat";

ifstream fsRead(input.c_str());

//cout << "Reading file: " << "\n\t" << input.c_str() << endl;

j = 0;

while (fsRead >> inval)
{
    Numpoints[j] = inval;

    //cout << Numpoints[j] << endl;
    j++;
}

j = 0;

fsRead.close();

...

[ITERATION LOOP]
{
int phase = it%T;

Ns = nearbyint(Numpoints[2 * phase + 0]);

ds = Numpoints[2 * phase + 1];

s = new double[5 * Ns];

if (phase == 0) phase = T;

    input += to_string(phase);

    input += ".dat";

    ifstream fsRead(input.c_str());

    //cout << "Reading file: " << "\n\t" << input.c_str() << endl;

    j = 0;

    while (fsRead >> inval)
    {
        if (j % 5 == 0) s[j] = inval + XDIM/2;
        else s[j] = inval;

        j++;
    }

    j = 0;

    fsRead.close();

...

delete s;
}
trincot
  • 317,000
  • 35
  • 244
  • 286
JHall
  • 73
  • 1
  • 1
  • 7
  • You really should not be using `new`. If you need an array of a run time size then use a `std::vector`. That said we will need a [mcve] here. – NathanOliver Jul 24 '17 at 11:53
  • I have to use 'new' because I'm sending variables to CUDA kernels. Regarding the example, I have tried but I can't reproduce these errors with anything other than this program and it's huge. – JHall Jul 24 '17 at 11:57
  • 1
    You still don't have to use new. You can get a pointer to the underlying data in the vector using the `data` function or `&vector_name[0]`. – NathanOliver Jul 24 '17 at 11:59
  • I am going to guess: You are debugging optimised code and/or code linked with duplicate COMDAT folding or similar. I.e. two functions have identical machine code, therefore sticking a breakpoint in one breaks in them all. – Ben Jul 24 '17 at 11:59
  • @NathanOliver I've tried that but it doesn't work with what I'm doing. Besides which using vectors significantly slowed down my program even before it was parallelised. – JHall Jul 24 '17 at 12:01
  • @Ben says No to Politics on SO Thats not the case. None of the breakpoints being triggered are in functions that I've written myself – JHall Jul 24 '17 at 12:03
  • That's irrelevant to my point. If you've linked statically they can still be duplicates of a function where you've set a breakpoint. Unset all your breakpoints, see if it goes away. – Ben Jul 24 '17 at 12:05
  • @Ben says No to Politics Just tried unsetting all my breakpoints, but no change I'm afraid – JHall Jul 24 '17 at 12:15
  • So are you sure they are breakpoints? Not some other type of exception? – Ben Jul 24 '17 at 12:35
  • @Ben says No to Politics on SO the message from Visual Studio: CUDA_IBLB_05.exe has triggered a breakpoint – JHall Jul 24 '17 at 12:39
  • That's something completely different. Putting that information in the question would have been a good start! https://stackoverflow.com/questions/10172436/c-error-on-ms-visual-studio-windows-has-triggered-a-breakpoint-in-javaw-exe – Ben Jul 24 '17 at 12:41
  • Possible duplicate of [C++ error on Ms Visual Studio: "Windows has triggered a breakpoint in javaw.exe"](https://stackoverflow.com/questions/10172436/c-error-on-ms-visual-studio-windows-has-triggered-a-breakpoint-in-javaw-exe) – Ben Jul 24 '17 at 12:41

0 Answers0