HOW can THIS cause an error?

Started by
43 comments, last by RunningInt 18 years, 5 months ago
if(numMarkers<1000) numMarkers++;assert(numMarkers<=1000);for(int i=0;i<numMarkers;i++){  assert(i<numMarkers && numMarkers<=1000);  marker.Blit(markers.x, markers.y);}


How does this read past the bounds? numMarkers is at most 1000, so i is at most 999.

However:

markers[markerIndex].x=(int)x+16;markers[markerIndex].y=(int)y+16;markerIndex++;if(markerIndex>1000) markerIndex=0; 


In this case, markerIndex can reach 1000 and cause an overflow.
Advertisement
DOH, you are right about that. but that doesn't fix the error... Also, I have gotten past that point while the program was running without a problem, the error occurs a good 30 seconds after that point, and after fixing that the error still occurs.
codeXtremeif(you->intelligence < radish->intelligence) you->STFU();
Quote:Original post by CHollman82
Quote:Original post by bakery2k1
We need to know more about the program since that line does not look like it can cause an error, so the real cause is probably elsewhere.


Exactly, but the real case is not elsewhere, I do absolutely nothing with the variable being compared, and without that line the program runs fine.
Someone responding like that DOES NOT want help, but simply wants to rant about their problem and blame the compiler.

Thankyou for calming down and allowing us to help you now.[smile]
We're working on it...
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Okay I've got nothing more than has already been mentioned so far. So Instead I have a question:

What happens if you comment out everything between BeginDrawing and EndDrawing? (besides not showing anything in the window any more)
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
For large bodies of posted code, one should use sources tags (hit the edit button on this post for an example - although you won't be able to actually edit my post, you will get the form all the same which will show exactly how I do it).

The example:

int main () {}
Quote:Original post by MaulingMonkey
For large bodies of posted code, one should use sources tags (hit the edit button on this post for an example - although you won't be able to actually edit my post, you will get the form all the same which will show exactly how I do it).

The example:

*** Source Snippet Removed ***
No kidding. I got through about 20 lines of that code before I quit.

---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage
I get this problem all the time when I use C (that's why I use Java for almost everything now...)

1. Turn on compiler warnings !!! They are tremendously helpful when debugging errors like this.

2. Re-check this line:

 DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);


I don't program DX/windows but make sure that lpdi is of the correct type.
Did you try removing "if(yppf<=0.0f && yppf>=-10.0f);" and testing the results? It should run normally, right?

Quote:"The instruction at "[some address in hex]" referenced memory at "[some other address in hex]". The memory could not be "written".


Does the "other address in hex" match the address of &ypff?
http://blog.protonovus.com/
if(markerIndex>1000) markerIndex=0; //This can reach 1000
if(numMarkers<1000) numMarkers++; //This can also reach 1000

Change it to:

if(markerIndex>999) markerIndex=0;
if(numMarkers<999) numMarkers++;

Even if that doesn't solve THE problem, it does solve A problem
Quote:Original post by RunningInt
if(numMarkers<1000) numMarkers++; //This can also reach 1000

Change it to:

if(numMarkers<999) numMarkers++;


Why ?

This topic is closed to new replies.

Advertisement