I've optimized some of my code and it helped a lot. I pretty much changed the areas where I've created a bitmap to create_video_bitmap and got a massive jump! But I have on problem.
I have a star class that creates a 1x1 video bitmap with and puts a pixel in the bitmap and moves the bitmap accordingly. And it seems to eat up FPS So, I was wondered, "why in the heck would I do that?", and quickly realized why I took that route. When I first wrote the class, I had it where the x and y values would be updated and then just have the pixels drawns at the desired coordinates, but when I do that, the exe crashes with a "alld42.dll access violation" under debug.
Here's the class:
1 | class star |
2 | { |
3 | public: |
4 | void init(int xlow, int xhigh) |
5 | { |
6 | //random_pick is a random number function I wrote |
7 | x = random_pick(xlow, xhigh); |
8 | y = random_pick(0, 480); |
9 | low = xlow; |
10 | high = xhigh; |
11 | started = false; |
12 | //starimg = create_video_bitmap(1,1); |
13 | |
14 | |
15 | |
16 | } |
17 | |
18 | void update(int off) |
19 | { |
20 | //off is the offset speed of the scroll of the stage |
21 | range = off; |
22 | |
23 | if(!started) |
24 | { |
25 | if(off == 0) |
26 | { |
27 | speed = 0; |
28 | } |
29 | else |
30 | { |
31 | speed = random_pick(off+1, off+range); |
32 | } |
33 | started = true; |
34 | } |
35 | if(started) |
36 | { |
37 | if(off == 0) |
38 | { |
39 | speed = 0; |
40 | started = false; |
41 | } |
42 | else if(curr_off != off) |
43 | { |
44 | speed = random_pick(off+1, off+range); |
45 | } |
46 | |
47 | |
48 | y+=speed; |
49 | |
50 | |
51 | if(y > 480) |
52 | { |
53 | reset(off); |
54 | } |
55 | } |
56 | curr_off = off; |
57 | } |
58 | |
59 | void draw(BITMAP* buf) |
60 | { |
61 | if(speed < 10) |
62 | { |
63 | putpixel(buf, x, y, makecol(255,255,255)); |
64 | } |
65 | if(speed == 10) |
66 | { |
67 | putpixel(buf, x, y, makecol(255,255,255)); |
68 | putpixel(buf, x, y+1, makecol(255,255,255)); |
69 | putpixel(buf, x, y+2, makecol(255,255,255)); |
70 | putpixel(buf, x, y+3, makecol(255,255,255)); |
71 | putpixel(buf, x, y+4, makecol(255,255,255)); |
72 | putpixel(buf, x, y+5, makecol(255,255,255)); |
73 | putpixel(buf, x, y+6, makecol(255,255,255)); |
74 | putpixel(buf, x, y+7, makecol(255,255,255)); |
75 | } |
76 | } |
77 | |
78 | void reset(int off) |
79 | { |
80 | range = off; |
81 | |
82 | if(off == 0) |
83 | { |
84 | speed = 0; |
85 | } |
86 | else |
87 | { |
88 | speed = random_pick(off+1, off+range); |
89 | } |
90 | x = random_pick(low, high); |
91 | y = 0; |
92 | |
93 | |
94 | } |
95 | |
96 | BITMAP *starimg; |
97 | int x; |
98 | int y; |
99 | int low; |
100 | int high; |
101 | int speed; |
102 | int low_speed; |
103 | int high_speed; |
104 | int r; |
105 | int g; |
106 | int b; |
107 | bool started; |
108 | int range; |
109 | int diff; |
110 | int curr_off; |
111 | }; |
I know I can change the putpixel to the color depth version and have, but had just changed it back to see if the color depth version was the problem is all. If I comment out the "y+=speed" then it doesn't crash, but of course the stars don't move either. Any suggestions?
Accessing video memory is so slow you should never do it. Try for example to fill the screen bitmap with putpixel in a double for loop. You will see how the screen is being slowly drawn and it will take seconds. That's how slow this is. And don't create 1x1 bitmaps, that just makes no sense...
The crashes you're getting might be because the clipping rectangle is not set or something. When you do a putpixel outside the bounds of the bitmap, it checks for inclusion in the clipping rectangle, but if that's not set properly, it can change memory it shouldn't have.
And don't create 1x1 bitmaps, that just makes no sense...
Well, yeah, I know that, which is why I'm asking the question in the first place. I wouldn't even have thought to even USE that process if it wasn't crashing to begin with.
The crashes you're getting might be because the clipping rectangle is not set or something. When you do a putpixel outside the bounds of the bitmap, it checks for inclusion in the clipping rectangle, but if that's not set properly, it can change memory it shouldn't have.
Well, all the random values should be within the dimensions of the buffer that I'm drawing the stars to. (0 - 640) x (0 - 480), but I'll do some more checking.
putpixel(buf, x, y, makecol(255,255,255));
putpixel(buf, x, y+1, makecol(255,255,255));
putpixel(buf, x, y+2, makecol(255,255,255));
putpixel(buf, x, y+3, makecol(255,255,255));
putpixel(buf, x, y+4, makecol(255,255,255));
putpixel(buf, x, y+5, makecol(255,255,255));
putpixel(buf, x, y+6, makecol(255,255,255));
putpixel(buf, x, y+7, makecol(255,255,255));
a vline() would be better.
> Any suggestions?
Run gdb and see what it can detect about the origin of crash.
In particular, even if the SIGSEGV happens inside an allegro function ,the stackdump should show which parameters you passed.
> Well, all the random values should be within the dimensions of the buffer that I'm drawing the stars to. (0 - 640) x (0 - 480), but I'll do some more checking.
Careful, your buffer is probably [0-639] x [0-479] . Boundaries included.
a vline() would be better.
duh!! hahaha! Thanks, AJ. I'll go ahead and put that in right now. I don't know why I didn't think of that!
Audric:
gdb. Is that within the debugging tool in msvc? I code in MSVC. I should've stated that earlier, sorry about that? If it's within the debugging tool, then I get the (alld42.dll) access violation message.
duh!! hahaha! Thanks, AJ. I'll go ahead and put that in right now. I don't know why I didn't think of that!
The Manual is your friend.
gdb. Is that within the debugging tool in msvc?
Gdb is the GNU debugger. Not applicable in your case.
if your using msvc
build the debug version of allegro.
link with the debug version.
then in MSVC-IDE hit F5 to run your application (with debugging)
That's what I've done already and I get the (alld42.dll) access violation message.
in what function ?
In this function that in the "include/platform/al386vc.h" file.
INLINE _AL_DLL uintptr_t bmp_write_line(BITMAP *bmp, int lyne) { _asm { mov edx, bmp mov ecx, [edx]BITMAP.write_bank mov eax, lyne call ecx } }
I just went ahead and just made a 1x1 gif file with a white background and drew it to the screen, because I really didn't want to spend this much time on this. It seems to work fine now. I just wanted to get away from creating bitmaps.