I'm trying to write a program to help manage production tasks in a game I'm playing. For the most part I can get the program to run fine; however I'm trying to write it so that I can use it for a longer period of time. To allow this I'm trying to set up a method that will increase the size of my storage array. I've managed to get my program working just fine if I DON'T try this and just set the original size to larger then the amount of data I'm trying to input, so I'm assuming the problem is contained within this method. When I am trying to use the method I get an Access Violation Error (compiles fine, only happens at run-time). I know this is somehow memory related, but I can't seem to figure it out. If anyone can come up with what might be wrong I'd greatly appreciate it.
I find it kind of odd that this error doesn't present itself right away. It doesn't seem to happen until the 32nd permutation AFTER the array size is increased (332 overall).
This is the structure
This is the actual methodCode:struct blueprint{ char *name; <-- memory for these is allocated elsewhere char *category; float wasteFactor; // Production/Research(r) time (in seconds) // int buildTime; int rMinTime; int rCopyTime; int rProdTime; ////////////////////////////////////////////// // Base Minerals Required // int tritanium; int pyerite; int mexallon; int isogen; int nocxium; int zydrine; int megacyte; //////////////////////////// int maxRuns; // Maximum number of runs per copy int batch; // Number of units made per batch };
Since the problem MIGHT be located elsewhere I'm attaching the full code as well.Code:void growArray(struct blueprint *array) { struct blueprint *buffer; int oldSize = size; size *= 2; buffer = (blueprint *)malloc(size * sizeof(struct blueprint)); for (int x = 0; x < oldSize; x++) { buffer[x] = array[x]; } array = buffer; }



LinkBack URL
About LinkBacks



)