Corrupte image

Blitz3D Forums/Blitz3D Beginners Area/Corrupte image

Fernhout(Posted 2006) [#1]
I did post this yesterday but can't find it anymore. So here the second time.
I load a BMP file in the program. The split it up in lines. redraw it on the screen using a sinus wave. In full mode the screen draws every time corrupted but. There come every time pieces of the desktop picture in the drawing???

This is the code i cant find any mistake...
Global Steps# 			= 0
Global Set_Point#       =0
Global Step_Count       =6
Global Off_Time#        =25
Global Timing
Global InitOn			=False
Global Title
Dim Wave_Screen(480)

Graphics 640,480,32

Title=LoadImage("Graphics/MainScreen.bmp")
Repeat
	sinewaveon()
	If KeyHit(1)
		End
	EndIf
	; finaly show update on screen
	Flip True
Forever
; Create a sinus wave on screen
Function Sinewaveon()
	If Steps#<3
		;If InitOn = False
			Cls
			; Setup screen
			DrawImage Title,0,0
			; Grab the line of the image
			For x = 0 To 479
				Wave_Screen(x)=CreateImage(640,1)
				GrabImage Wave_Screen(x),1,x-1
			Next	
			;SetBuffer BackBuffer()
			InitOn=True
		;EndIf
		Steps# = 8.0
		Set_Point#=0
		Step_Count=6
		Off_Time#=25
		Timing=MilliSecs()
	EndIf
	Cls
	;Draw in sinus mode
	For x = 1 To 479
		DrawImage Wave_Screen(x),Sin(Set_Point#+x*Steps#)*Off_time,x-1
	Next
	Set_Point#=Set_Point#+Step_Count
	;Calculate new sinus wave
	If MilliSecs()=>Timing+25
		Steps# = Steps# -0.05
		Off_Time=Off_time-0.25
		Timing=MilliSecs()
	EndIf
	
	If GetKey()<>0 Or GetJoy()<>0
		Case_Active =2
	EndIf
End Function



Fernhout(Posted 2006) [#2]
P.S. Mainscreen.bmp is a 640 by 480 bitmap picture. Any picture i use give the same problem.


b32(Posted 2006) [#3]
I believe Blitz has troubles with images that are greater than it's graphics mode. So try setting the graphicsmode to 800x600 ?


Fernhout(Posted 2006) [#4]
Thanks but i need the 640x480 mode. Outherwise the configuration of the drawings are not ok its for a computer who have the max 640x480. And the drawing is the same size as the graphics mode. I did try bringing the depth to 32 bits. But even that won't work. I Did try somthing else and the same result.
Maybe i can post it as a bug.


b32(Posted 2006) [#5]
Even though you need 640x480, it may make sense trying to set the graphics size bigger than the image in an attempt to find the cause of this bug. One of the loop goes from 0..479 and the other one from 1..479. The first loop causes GrabImage to grab an image at (0, -1). I did run the code and it works (very nice). To run it, I pasted the function into the main loop. I did that to avoid defining all variables globally. One other thing you could try is using CopyRect instead of GrabImage.


Fernhout(Posted 2006) [#6]
I don;t know what the problem is. I did resize the screen to 800 x 600. and try run it. The same problem. I did CopyRect. Run it and also the same problem. Maybe its something to do with DirectX. That was last time a problem. All my games didn't start. I did reinstal it and after a couple of tries it worked again.
If i grab the hole screen and move it over the screen in all kind of directions its working fine. Even to let it follow the mouse it does not give any problem. But as soon i grab a 1 pixel height line its going wrong. The line is corrupted. This happend only if i use to grab and draw a line. Up to for lines it is going wrong. As soon i grabbing 5 lines everything working ok. Thats wat bugging me. I hav already change the program. But i want to have it working.


b32(Posted 2006) [#7]
That is very strange :( He, the code lacks a SetBuffer BackBuffer() after Graphics, is that on purpose? And I think it is better to adjust the first loop to start at 1 instead of zero. You shouldn't grab images outside the screen. Maybe you should rebuild the code step by step and see at what point it goes wrong.


Fernhout(Posted 2006) [#8]
I know that in this example laks Setbuffer Backbuffer(). I was forgotten that to put in. But in the working code it is in. Your suggestion to use CopyRect was used to. Even on that i got the same problem. I have another copmuter by the hand and wil try to install Blitz3D on that computer. On that computer is stil the version directX 8.1 on it. If the code is working on that computer than i know that its not Blitz3D who give the problem but DirectX. I am suspecting that DirectX is the problem. Because you already say's that the code works on you computer.
I have two reasons why i suspecting DirectX.
1. A few mounths ago after installing a game my DirectX was corrupted. Game did not started and a lot of other games did not run anymore. All giving the same error. I did reinstall DirectX. And the only way to install it was in save mode.
2. I did updated another Basic (Dark Basic) And that basic needed a new type of DirectX. They delivered it also in the update. Is was Redist.exe version Directx 9.0c August 2006. All games working except Settlers 2 10th anniversary.
And now blitz3d.
I can't deinstall this version of directX. I did try it using differend programs. All say the same. This version is not supported.
So in a nut shell. I'am stuck whit what is got. I can not reinstall the computer because its a company computer.
So the wait is for the test on the other computer. And a wait for a new version of DirectX.

Al in one. Please stay giving me responce so that i can find a solution for this.


b32(Posted 2006) [#9]
That's a real shame :/ .. I does sound like DirectX is the problem. Or maybe the graphic drivers, I have a NVidia card and it gave me problems using PickedSurface.
Uninstalling DirectX seems to be a big problem, but maybe you could use system restore if you're on XP ? I tried to write some code that does the same as yours, sort of as a checkup:

I think you can make a workaround for this trouble, since images with a height of 5 are working, create the images at 640x5, but only CopyRect one line on it. This way you'll need 4 times more memory, but you can avoid this nasty bug. And have you installed the lasted Blitz ? Maybe you could try downgrading to a previous version.

(edit)
He, I was thinking .. maybe you could load the image with LoadAnimImage, and then set the tilesize to 640x1 ..


Fernhout(Posted 2006) [#10]
Nice thinking. You solution did not work on my computer. You siuwave was realy nice. Sorry. unfortunately LoadAnimeImage need a film strip of images from left to right. And not up to down. Thats a shame.

I have found the problem anyway. I had the opportunity to try the program on two diffend computers. One had Directx 8.1 and the other 9.0c Microsoft production. Both did run the exe and the there one compiled progam. And both run the program without any problem. And the real luck was that one computer was the same as mine. So i am now realy sure that the problem is DirectX. Now i must find a solution to resolve this problem. A rolback is not possible because there are a lot of programs who are installed after the directX update. So if anyone have a solution for me they are realy realy welkom.


Fernhout(Posted 2006) [#11]
I have solve the problem.I found the DirectX bug ( At least somebody wo knows a lot of DirectX) . And have made a workaround for it. Its even working on the other computers to. So program fixed.

The solution: Its stupid but its work.
The mistake that DirectX make is that every odd liven is a interlace line. This mean that the odd lines are desktop lines. This means that i only can use even lines to grab a image. I load the image 2 times in the program. One starting on line 1 and one starting on line 2. Then reading every line in by switching the reading image. And when i done that i can use all the lines to draw on the screen. No distorsion what so ever. In a nice sinus wave. Thanks for the help. This is maybe somthing for people who had simulair problems.

This bug wil be fixed in DX10. They made this bug in the progam by mistake. To preserve the desktop the image is tranfered to memory. but somhow its overlaying the other memory bank that Blitz3D use. They call it interlace screening.


Sir Gak(Posted 2006) [#12]
Thanks for posting the solution.


Gillissie(Posted 2007) [#13]
Fernhout,
Can you please post some code of your solution? I don't really understand your explanation. I have a user with corrupt images in my game too, but I can't figure it out. I'd like to see what you did to solve your problem.


Fernhout(Posted 2007) [#14]
I hope you will find what you need. As the sound of it you have did update DirectX also on the wrong way. anyway hier is the code.
Function Sinewaveon()
	If Steps#<3
		;If InitOn = False
			Cls
			; Setup screen
			DrawImage Title,0,0
			; Grab the line of the image
			For x = 0 To 479 Step 2
				Wave_Screen(x)=CreateImage(640,2)
				GrabImage Wave_Screen(x),2,x-1
			Next	
			;SetBuffer BackBuffer()
			InitOn=True
		;EndIf
		Steps# = 8.0
		Set_Point#=0
		Step_Count=6
		Off_Time#=25
		Timing=MilliSecs()
	EndIf
	Cls
	;Draw in sinus mode draw even lines odd lines is desktop image
	For x = 0 To 479 Step 2
		DrawImage Wave_Screen(x),Sin(Set_Point#+x*Steps#)*Off_time,x-1
	Next
	Set_Point#=Set_Point#+Step_Count
	;Calculate new sinus wave
	If MilliSecs()=>Timing+25
		Steps# = Steps# -0.05
		Off_Time=Off_time-0.25
		Timing=MilliSecs()
	EndIf
	If Steps#<3
		Case_Active=2;Bring the sparks on line
	EndIf
	If GetKey()<>0 Or GetJoy()<>0
		Case_Active =3
	EndIf
End Function


you can update your DirectX again if you like. After installing this your problems will be solved.

directx_dec2005_redist.exe