Hey,
I have a problem.
I have 10000 Tiles, all with a size of 10 times 10 Pixels.
I give them their positions like this:
Meanwhile they get projected on the screen like this:
getPositioned(short, short) just give them Tiles their positions, defined in the class TILE as *x_pos and *y_pos.
Its kind of all working.
But as you can see in my screenshot
,
(bigger that you can see something here: PICTURE
there is something weird happening in the 12/13 row from bottom.
I dont know what this is.
I have some routines, that some things happen, when I click on a TILE,
but when I click on TILE in the 12th row from bottom, it activates one in the 13th.
But just sometimes. So I dont know what this means, I am pretty sure, I did my math right.
Somebody can help me?
EDIT: Screenshot is not very good.
DB should be better!
Nico, you're using a triply nested loop. You only need a doubly nested loop. All iterations of i < 9999 are overwritten by the inner xy loop when [i = 9999].
Thx for answering me.
I wrote it down like that now:
But its still not working!
You can combine those two methods into one.
Make the draw method take an x and y pos. Then you don't even have to store the position.
I can't see why it's not working just from the little bit you've shown me. Show more code.
No, I need to store the position, I need it later.
What else do you want to see?
My drawing code is still the same!
I just want to store the positions in the vector (which I do with my new code), and then draw it.
I dont understand why it isnt working.
for (int i = 0; i < 10000;) { for (int y = 1; y <= 100; y++) { for (int x = 1; x <= 100; x++) { (*tiles)[i].getPositioned(x * 10, y * 10); (*tiles)[i].draw(); i++; } } } //POSITIONS
You are drawing 10000 tiles 1000 times each. That is what the question or response was about.
How big is 1 tile?
Each tile gets drawn
for (int y = 1; y <= 100; y++) { for (int x = 1; x <= 100; x++) { // draw tile } }
Look at my new code, but even in the old one:
I draw each tile one time. The index "i" is increasing with each loop.
In my first code there was a problem, because when "i" was 9999, it would get overwritten by the inner loops.
In my new code this isnt the case.
I am debugging my code, and when I view my vector "tiles", everything is alright.
Each TILE has the right position, as I see it.
So I dont know, why there is something wrong in the projection.
I hope you understand my english XD
What are the values of status and bomb at those locations that are drawn funny?
What do TILE_BITMAP_NORMAL, TILE_BITMAP_RED, TILE_BITMAP_GREEN look like?
Some things I question:
What is *status, *x_pos and *y_pos? Why are they pointers and being dereferenced?
Can *status be anything but 1 or 2?
Okay, that are many questions.
I use pointers, because in this project memory managment is very important.
While the TILES are drawn the first time, *status is 1 for EVERY Tile.
That means, that there are only TILE_BITMAP_NORMAL drawn.
What the TILE_BITMAP_NORMAL looks like, that can you see in my screenshot.
But while you say it, I changed the bitmap.
Here is the screenshot, on it you can see even better what I mean:
PICTURE 2
*bomb is of course in that state always 0, but that doesnt matter, because the *status is never 2, so it doesnt get in that if-clause.
And *x_pos and *y_pos are attributes in my vector<TILE>, which every TILE gets in the xy-loop, as in the code above.
I'm more curious as to how these variables are created and modified. Are these variables actually allocated and deallocated in your routines?
I use pointers, because in this project memory managment is very important.
Using an integer vs an allocated integer isn't going to save you memory.
No, but I can controll it. Dont mind it, it has nothing to do with the error.
Look,
I overwatch my (*tiles) vector. And all the variables are correct.
I had an excellent Idea.
After every (*tiles)[i].draw() i would do a al_rest(0.01).
And the positions are all correct.
Its just drawing the bitmaps wrong. Sometimes.
I even made a video, please look at it.
Maybe it can tell you more than it does to me.
VIDEO
Of course the Video Quality is super shitty, because I just have the free version and probably a bad PC, but you can see a little bit.
You can see, that every row and every line is drawn correctly.
Everytime you see a grey ... something, there is missing a line.
In the screenshot SCREENSHOT you can see with good quality what I mean!
Oh, and to your question.
These variables get standard constructed when creating my vector<TILE>.
Are you drawing directly to the display or to a separate bitmap which is then drawn to the screen scaled?
As Edgar suggested if you could provide more source code (only code related to the drawing - no need to disclose your entire program logic) or create a small separate project that re-creates the issue so we could test on our end it would greatly help in understanding the problem.
I am drawing directly to the Backbuffer.
And I dont understand to what you want to see more code.
Thats all there is related to the drawing.
I give them tiles their positions, and then I draw them on the buffer.
After that whole routine, I do an al_flip_display(), and thats it.
PLS CAN SOMEBODY HELP ME (((((((((((
I get desperate!
Trying to fix this shit for more than 24 Hours! :,(
Dude. Even I need to sleep once in a while.
EDIT
Often, the problem has nothing to do with the code you think it does. That's the messed up beauty of coding. If you want me to help, show more code, like your Tile class.
Okay, here you go:
Header
SOURCE
In my main I just make a GAME newGame;
This code is wrong, but it's not necessarily the problem.
void TILE::DELETE() { x_pos = NULL; delete x_pos; y_pos = NULL; delete y_pos; x_size = NULL; delete x_size; y_size = NULL; delete y_size; status = NULL; delete status; bomb = NULL; delete status; }
That's the same thing as xpos = 0; delete 0;. Which means it is a memory leak.
There's no reason to be using dynamically allocated memory. You're over engineering the problem.
Something else to keep in mind is the Rule of Three.
You need to learn the difference between a shallow copy and a deep copy.
You need to learn the difference between the heap and the stack.
Look up RAII.
I still need to see more code.
[PART 1] (seems to long for a post)
There is not much more code right now XD
But I dont get why do you want to see more code.
I debugged the program to this point, and thats exactly the point where it is already drawn wrong. I mean, everything is there.
I give the positions, i draw them with this positions.
I can give you the part, where my newgame is allocated, but I dont know if thats for any help.
You know what, I give you the whole code.
minesweep.cpp
global.h
global.cpp
Please write something, so I can make the part 2 with game.cpp
and game.h
The problem is here :
The code I quoted is run every time an event occurs. This means I need to see the GAME class.
It looks like a classic memory leak and dangling pointer.
Note that you're doing the same thing I warned you about before.
You're calling delete 0; again.
[PART 2]
game.h
game.cpp
Yea, I know, but the GAME is going in a loop and stays there.
So this shouldnt be a problem.
If you know what I mean
Hi Nico,
from what I can see your code looks OK. It is possible that something is wrong with the data used to draw the bitmaps and I believe Edgar will have a quick look to try to help you with this.
I am not an expert so I cannot help much but maybe you can try this (just for test):
-because your screenshot is in HD and you are creating a full hd window maybe try running your program with 650x650 window and see if the problem repeats (you might need to multiply the x and y position with 5 instead of 10 for the entire map to fit in the window)
-also, try running your program in full screen(using native resolution of your monitor) and see if the problem repeats
If you have the time to try these two things it is possible we can isolate the problem to a graphics end instead to memory data.
Hey Miki,
Fullscreen I already tried, it was the same.
And the resolution wont work because the bmps are 10x10 Pixels.
I can try to do the resolution with scaled bitmaps, but that I have to do later, because I am outside.
Your code keeps changing. Where is your draw routine called now?
Also, besides the very beginning, do you draw your tiles at any other point?
EDIT: oh I see under your mouse event
What does this code do?
void GAME::drawGraph() { for (int i = 1; i <= 10000; i++) { al_draw_pixel((i/25 + 1100), (EXPONENTIAL(i)/25 + 300), *RED); } al_flip_display(); }
Can you create a temp bitmap of the size of the grid? Draw the tiles to the temp bitmap and save it. Then upload as attachment. Just the tiles before anything else is done to them.
Just some helpful criticism, keep you logic separate from your drawing.
All drawing should be done in one place. You can use states and variables to differentiate what is drawn.
Yeah, thats true, but actually I have just one place where the most is drawn.
TILE:draw()
The GAME:drawGraph() just happens one time.
And I mean, you have the code, what dont you understand in it.
It plots a function on the screen.
I will try this with the temp bitmap.
You mean, i should create a new bitmap, set it as a target and save it as file?
Or what exactly do you mean?
1st, fix your memory leaks.
Delete pointer then set to null
See if that does anything. Is it a memory leak issue or not?
2nd, are your bitmaps being loaded correctly? You don't check. I don't know what your tile bitmaps look like so I don't know.
3rd, My suggestion was yes to create temp bitmap, set as target, draw, save, delete. This should be done before any logic or loops.
You can add the image as an attachment like so
{"name":"612184","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/f\/8fd36c1ad264f294fee9c0ecf7c4fc4a.png","w":1920,"h":1080,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/f\/8fd36c1ad264f294fee9c0ecf7c4fc4a"}
4th, try a small program. Load 1 tile and draw the same 100x100 grid.