Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbBox() loop help?

Author
Message
FlexiCat
14
Years of Service
User Offline
Joined: 15th Jun 2010
Location:
Posted: 11th Jun 2011 05:37
Hello forum.

I am new here but first let me say i have searched around a bit but i think i am lacking some keywords to find what i am looking for.

I have a loop that draws a dbBox() on the screen in the places that correspond to a 2d array called map. so if any given slot on a map = 1 then i draw a box in its corresponding place.

This drawing function is called within the while (loopGDK) thing from the example/wizard thing.

My problem is nothing is showing up at all. i have tried calling the drawing function outside of the loop and the same thing happens. at one point before i got the drawing loop done i had managed to make it draw then entire designated map space RED, this happened because i forgot to make it only draw when the array entry = 1. however i cannot replicate this either.

this is my code to draw it:


it is pretty simple and i have done something practically the same as this a few times before in java script (yes i understand the differences) however i just cannot seem to get it to work.

NOTE: possible unrelated as i am not sure when it started happening (ie. before or after i started doing the dbBox draw loop) but i now cannot close the program by pressing escape or even by pressing the X on the top right of the window any more it just throws an un-handled exception. maybe completely unrelated and just something else i broke but thought it may help.

Thank you in advance and if you need more code to help me sort this out just ask.

thank you very much guys,
Nekroze

I swear to the programmers bible that I shall not harm the FPS.
FlexiCat
14
Years of Service
User Offline
Joined: 15th Jun 2010
Location:
Posted: 11th Jun 2011 06:09 Edited at: 11th Jun 2011 07:35
UPDATE:
The issue mentioned in my "NOTE:" is indeed somehow caused by my making a new instance of my map class... however i don't see how this could happen.

I am going to include a zip of my source (its very small its just this map class and its contents) please can anyone review what is going on?

EDIT: if i comment out my destructor for the map class it crash error thing becomes more descriptive when i try to close it. now it says:
Quote: "A buffer overrun has occurred in InfiniQuest.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program."


sorry to have to dump my whole project piece so far but idk what's up with this.

Thanks again all,
Nekroze

I swear to the programmers bible that I shall not harm the FPS.

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Jun 2011 11:24
Your loops are strange. It seems you mix the concept of the for loop with the while loop. In a for loop, you don't need to define a second loop variable and increment it yourself, because you already have a loop variable (defined in the for header).

Also, arrays in C++ are indexed from ZERO, not from 1. Always. If you have an array map[10][10] and try to index it until 10 and not from 0 to 9, you will have a buffer overrun (or memory access violation) error. Or maybe the program will continue to run but won't do what it's supposed to do.

I rewrote the code you posted above with these corrections. Note that the calculation of coordinates in dbBox also changes because of the corrected indexing.



I corrected the loops, tested the program and... nothing shows up on the screen, so give me some more time to find out what else is wrong. I'll post again later.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Jun 2011 13:16
OK I've got the remaining problem. The brackets were missing from the coordinate calculation:



This is with the corrected loop, but the brackets are missing in your original code too. If you write "CurX - 1 * tileS", it means that tileS will first be multiplied with 1, then the result is deducted from CurX, so the result is actually CurX - tileS. This is because the precedence of multiplication and division is higher than addition and subtraction. If I correct this as well, then your map works.
FlexiCat
14
Years of Service
User Offline
Joined: 15th Jun 2010
Location:
Posted: 11th Jun 2011 16:42
awesome, thanks for the maths part i figured out the second part with the () for the separating the maths. your advice fixed the buffer overrun thing very nicely, thanks mate.

I swear to the programmers bible that I shall not harm the FPS.

Login to post a reply

Server time is: 2024-10-02 17:20:46
Your offset time is: 2024-10-02 17:20:46