Bug with Linedrawing in buffer?

Blitz3D Forums/Blitz3D Programming/Bug with Linedrawing in buffer?

Marcell(Posted 2005) [#1]
I'm making a game. I have strange problem when drawing a figure from Bank (the coord offsets are stored there). Everytime I use my figure drawing code, I get some mess in screen, when the score variable reaches about 200000 in example program below. This problem does not occur with my laptop. The machine this bug comes up has Radeon 8500LE and hangs up occationally with some 3D games with which my laptop does not hang up. Do I do something illegal in the following code? Should it work? It does work without any bugs with my laptop.

The bug appears with the code line Line 40,40,100,100: the line is duplicated with pixel mess. And sometimes the debugger tells that there's memory access violation with lines where the figure is drawn. Offsets and coords are ok.


figure\lineBank = figure_up\lineBank

While Not KeyHit(1)
SetBuffer ImageBuffer(gfxActionBuffer)
Line 40,40,100,100
GrabImage gfxBufferInside,0,0

SetBuffer BackBuffer()
DrawImage gfxBufferInside,XStart,YStart

Text 90,225,score%
score% = score% + 3

For j = 1 To BankSize(figure\lineBank) Step 4
Line ox+PeekByte(figure\lineBank,j-1),oy+PeekByte(figure\lineBank,j),ox+PeekByte(figure\lineBank,j+1),oy+PeekByte(figure\lineBank,j+2)
Next

Flip

Wend
End


VP(Posted 2005) [#2]
You're going from 1 to BankSize+2 in the final loop.

for j = 1 To BankSize(figure\lineBank) Step 4
Line ox.......+PeekByte(figre\lineBank,j + 2)
                                          ^^^


Also, have you CreateImage()'d gfxBufferInside ?


Marcell(Posted 2005) [#3]
Thanks! I didn't notice that myself, silly me!
I do exceed the legal area. I was always sure, that the problem was with this figure linedrawing routine, but somehow I was blind for the bug.

Yes, I have used CreateImage() with gfxBufferInside.

Again, thank You very much!


Marcell(Posted 2005) [#4]
Hmmm, I checked, j gets values 1,5,9,13,17,21,25,29 in the for loop if I have 32 as bank size.

In the line drawing for-loop the offsets are fetched from positions 0-31 from the bank. So I don't exceed the bank limit. Still, the bug occurs. Strange, with this small code I get the bug into screen only with that line drawing code from bank, but to witness the bug I have have also "Line 40,40,100,100" code line so that I can see the mentioned pixel mess.


VP(Posted 2005) [#5]
You're pokeing and peeking bytes. Sure you're wanting bytes and not ints? Doesn't look like it but it's hard to tell without the full code.

I think it might be some other part of your code causing an error.


Graythe(Posted 2005) [#6]
It might be a @#!*y memory location. That could be a graphics card problem but on lower spec desktops may indicate an onboard memory problem. RU overclocking any part of your system?


Marcell(Posted 2005) [#7]
No, there's no overlocking.

In the full code I do most of the linedrawing in the gfxActionBuffer. In the example code above I have reduced the code to the minumum where the bug occurs.

I myself don't find anything "illegal" there. If I comment the for-loop away, I don't get the bug. If I keep the for-loop, but comment "Line 40,40,100,100" away I don't at least see any bugs. In the full code there's more drawing. If I don't use any Line-commands, only Rect-commands (screen offsets are fetched from Bank too) I don't get, or at least see, the bug.

I might try later use ints instead of bytes. Should it still work, if I add byte values into screen coordinates that are ints?

The problem may be with my hardware (the machine boots itself occationally, hangs up and so on, still with other applications I haven't seen drawing bugs); with my laptop the full code seems to be ok.


big10p(Posted 2005) [#8]
Repost the code as it is now, having sorted the bugs others have pointed out. I suspect you're peeking/poking values outside you're bank's bounds, still. You can only access bank bytes from 0 to BankSize(bank)-1. Anything outside this range is illegal.


Marcell(Posted 2005) [#9]
The following code is shortest test code I have, where I get the bug (not with my laptop). When score variable reaches about 300000 I seem to get the bug.

(How can I post the code as it should be posted as vinylpusher posted above?)

Graphics 1024,768,32,1

Const blocksize = 10

Type B_FIGURE
Field lineBank
End Type

Type C_FIGURE
Field lineBank
End Type

figure_up.B_FIGURE = New B_FIGURE
figure.C_FIGURE = New C_FIGURE

figure_up\lineBank = CreateBank(8*4)
figure\lineBank = CreateBank(8*4)

gfxActionBuffer = CreateImage(180,360)
gfxBufferInside = CreateImage(180,360)

For i = 0 To BankSize(figure_up\lineBank) - 1
Read value
PokeByte figure_up\lineBank,i,value
Next

figure\lineBank = figure_up\lineBank

While Not KeyHit(1)
Cls

SetBuffer ImageBuffer(gfxActionBuffer)
Line 40,40,100,100
GrabImage gfxBufferInside,0,0

; Gosub drawIntoScreen

SetBuffer BackBuffer()
DrawImage gfxBufferInside,340,170

Text 90,225,score%
score% = score% + 3


For j = 1 To BankSize(figure\lineBank) Step 4
Line 440+PeekByte(figure\lineBank,j-1),170+PeekByte(figure\lineBank,j),440+PeekByte(figure\lineBank,j+1),170+PeekByte(figure\lineBank,j+2)
Next

Flip

Wend
End

Data blockSize,0,2*blockSize - 1,0
Data blockSize,0,blockSize,blockSize - 1
Data 2*blockSize - 1,0,2*blockSize - 1,blockSize - 1
Data 0,blockSize,blockSize - 1,blockSize
Data blockSize*2,blockSize,3*blockSize - 1,blockSize
Data 0,blockSize,0,2*blockSize - 1
Data blockSize*3 - 1,blockSize,blockSize*3 - 1,blockSize*2 - 1
Data 0,2*blockSize - 1,3*blockSize - 1,blockSize * 2 - 1


big10p(Posted 2005) [#10]
OK, to start with, I don't know why you're creating 2 banks but only using one. The line 'figure\lineBank = figure_up\lineBank' just makes figure's bank handle point at figure_up's bank. Doing this, you've now lost the handle to figure's bank.

P.S. The forum codes are here:
http://www.blitzbasic.com/faq/faq_entry.php?id=2


Marcell(Posted 2005) [#11]
I'm making a Tetris kind of game. The Tetris-blocks are defined in BLOCK-type. Current block is defined in CBLOCK. That is why there's that figure\lineBank = figure_up\lineBank line. Could this cause a memory leak? A bank is created into figure\lineBank, but never used; instead figure\lineBank is made to refer to another bank.


Marcell(Posted 2005) [#12]
I tested, if I use only one bank and read values from there, I still get the bug...


Marcell(Posted 2005) [#13]
I tried figure-drawing from an array without using a bank, still got the bug. If I comment out the 3 lines where the figure is drawn in for-loop, I don't get the bug. So, it seems, that if there is something wrong with code, it should be in the for-loop. But really can't find anything wrong there... Should I suspect the problem is with my hardware (the machine hangs up occationally with some 3D games and so on (though, I have not had any drawing bugs with any other programs))? With my laptop the whole game program works fine.


big10p(Posted 2005) [#14]
Sure sounds like a hardware issue, then. Try the usual driver shuffling to see if that makes a difference. Could also be a hardware fault, though.


VP(Posted 2005) [#15]
I could not reproduce the error at all. It must be something specific to your machine.

Are you using Blitz3D 1.91? Do you have an AGP graphics card (and is your AGP aperture set to 64MB in your BIOS)? Do you have antivirus or antispyware software active?

What processes are running on your machine (can you alt+PrtSc and post an image of your task manager tasklist?).

With you mentioning that your Radeon locks up in other games (not just blitz) it sounds like there is a problem with the RAM on your Radeon (probably not the core, you'd have to work very hard to kill a Radeon core). Was it, or is it overclocked? Does the fan on it work? Does the inside of your PC feel very warm when you take a side-panel off our case? Is there dust in the Radeon?

Too many questions, I know, but I'm just trying to eliminate things until the problem reveals itself!


Marcell(Posted 2005) [#16]
Hmmm, I tested the program without Radeon, with motherboards's plain VGA and it worked, no bug! The bug may have hade something to do with Radeon's drivers.

My Radeon 8500LE is AGP card, no overlocking, Blitz IDE is 1.87, linker 1.64, runtime 1.87, I have AntiVir antivirus on background.


VP(Posted 2005) [#17]
Marcell: Blitz 1.91 has been available for a number of weeks. You should really upgrade. You might want to temporarily uninstall your antivirus software to see if that eliminates the bug.

Make sure you have the latest Catalyst drivers for your Radeon. if the bug stil happens, try an older version of Catalyst.

If you still get the bug (and your other 3D games keep crashing as well) then I'm afraid it might mean your Radeon is faulty.