Jump to content
  • Advertisement
Sign in to follow this  
Sc0rPi0n59

confusing problem with deletion

This topic is 4255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So heres the deal, i need to run a method a few times with different params and for some reason, the first time i call this method it works seamlessly and has no problems, but any subsequent calls to the method crashes, not sure why, read the comments for further explanation: // I've cut out the unimportant stuff from this method, or at least the stuff // which had nothing to do with currSequence, which seems to be where the // problem is. void doSearch(SearchType* mySearch, long listSize) { //... a few initializers, just setting values to some ints and floats // so the first time this method is called, it prints out "crash1" and // "crash2", but the very next call to this method prints only "crash1" // and then prints: "Segmentation Fault (core dumped)" cout<<"crash1"<<endl; float* currSequence = new float[listSize]; cout<<"crash2"<<endl; for(unsigned int i=0; i<numOfSequences; i++) { // fillin() takes a method and fills it with random vals fillin(currSequence, 0, listSize, 0.0, listSize); for(unsigned int j=0; j<randomNumsSize; j++) { // mySearch takes the given search algo (from the // params) and performs the search on the sequence temp = mySearch->search(currSequence, randomNums[j], listSize); // ... extra statistical functionality } } // some basic output stuff delete[] currSequence; currSequence = NULL; } I have no idea what the problem could be, im actually usually a java programmer so this would normally work in java and i have no idea why it doesnt work here, any suggestions??? Thanks!!

Share this post


Link to post
Share on other sites
Advertisement
My first guess is that your fillin or search functions are stomping on memory. Try taking out those calls and see if it still crashes.

Share this post


Link to post
Share on other sites
well you were right, it was fillin thats taking up my memory, but can you look at fillin() below and tell me where it might be messing up?

void fillin(float X[], int a, int b, double low, double high)
{
/* * * * * * * * * * * * * * * * * * * * */
/* Fills in cells of vector X[] */
/* ( locations X[a]... X ) */
/* with strictly increasing real values */
/* that are more than "low" */
/* and less than "high" */
/* * * * * * * * * * * * * * * * * * * * */
int indexrange, index;
double valuerange, value;

indexrange = b - a;
if (indexrange<0) return;
index = a + (.25 + .5*dshrandom(0))*(indexrange+1);
valuerange = high - low;
value = low + (.25 + .5*dshrandom(0))*valuerange;

X[index] = value;
fillin( X, a, index-1, low, value);
fillin( X, index+1, b, value, high);
}

Share this post


Link to post
Share on other sites
The value you generate for index is probably going out of bounds. Keep in mind that indexes begin at 0 and go to arraysize-1, not arraysize.

Try printing out the generated index each time and see what it's doing.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!