Getting a Heap Corruption, help me find the bug please?

Hello all,

I am getting this heap corruption in my code that I have never seen before.
I have read a little bit about it, but I can not seem to find where the bug could be in my code.

Here is the part of the code that the program makes it to.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// process user input
   userInput(ship, records);

   for (int j = 0; j < records; j++)
   {
      convertedWeight = weightToEarth (ship[j].pickUpWeight, ship[j].pickUpPlanet, planet);

      deliveryWeight = weightToDeliveryPlanet (ship[j].pickUpWeight, ship[j].deliveryPlanet, planet);

      ship[j].distance = distanceTraveled (ship[j].pickUpPlanet, ship[j].deliveryPlanet, planet);

      travelTime (ship[j].speed, ship[j].distance, ship);

      outFile << "            Shipment # " << (j + 1) << "\n\n"
         << "Cargo Type:   " << ship[j].cargoType << "\n"
         << "Weight Of Cargo - Earth Pounds:   " << convertedWeight << "\n"
         << "Weight Of Cargo - Delivery Planet:   " << deliveryWeight << "\n"
         << "Shipment Travel Distance:   " << ship[j].distance << "\n"
         << "Travel Time:\n"
         << "Hours - " << ship[timeCount].travelTime << "\n"
         << "Days - " << ship[timeCount + 1].travelTime << "\n"
         << "Years - " << ship[timeCount + 2].travelTime << "\n\n\n";
      
      // debug line
      cout << "made it past " << (j+1) << " loops";

   }


It makes its past one loop in the code and then I get:

Windows has triggered a breakpoint in Project 5.exe.

This may be due to a corruption of the heap, which indicates a bug in Project 5.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Project 5.exe has focus.

The output window may have more diagnostic information.

I can post the functions if you guys would like to take a look. Just trying to keep the code short right now
Last edited on
it also does not make it back to the beginning of the loop. It completes one loop but doesnt make it to the beginning, it ends after the debug message
Last edited on
omg never i fixed it... It was because in the struct I had declared, i had a "record" member in there. I also used the variable record in main to process the amount of shipment records to be sent. For some reason this caused some failure in the code.


BUT now a whole new error... haha this time a different heap corruption ugh
Last edited on
Topic archived. No new replies allowed.