Problems with windows lock and loadimage

BlitzMax Forums/BlitzMax Programming/Problems with windows lock and loadimage

Josepho(Posted 2008) [#1]
My game crashes when i load images while i have my windows locked. I use the directx7 driver, is this a bug? can i fix it?


MGE(Posted 2008) [#2]
Post some code that does the same thing so we call can have a look and verify the problem.


Josepho(Posted 2008) [#3]
Graphics (800,600,0,0)

Repeat
Until KeyHit(KEY_ESCAPE)

Global i:Int
Global image:timage
Repeat
i:+1
Print i
image=LoadImage("image.png")
Until i>10000



Repeat

Cls
DrawImage(image,10,10)
Flip

Until KeyHit(KEY_ESCAPE)

If you are in windows vista press the windows key and L during the second repeat iand the game will crash. How can i fix this? :(


Josepho(Posted 2008) [#4]
No replies? Anybody knows how can i fix this? Its important! If you want to test it, "image.png" can be any png file that you want


Zeke(Posted 2008) [#5]
works fine here. tested twice and app is running well when windows is locked.

Vista 32-bit Home Premium
Radeon HD 3650


grable(Posted 2008) [#6]
Works fine here too, and im running Windows XP.


Josepho(Posted 2008) [#7]
Maybe you need to try to change the 10000 to a higher number, or maybe the kind of png that im using is part of the problem. You can download it here




Uncle(Posted 2008) [#8]
Works fine here as well with the png you supplied. I find it odd though that you would want to load 10,000 images. Does your application really need that many?


Josepho(Posted 2008) [#9]
No, this is just an example code that has the same crash of my project, my project loads a lot of diferent images but when i make windows+L during the image load it crashes -_-. I dont know what im making wrong, i know that my application crashes in other pcs too, am i missing something that i have to do in blitzmax?


Josepho(Posted 2008) [#10]
Anybody knows anything about it? Its very urgent


Perturbatio(Posted 2008) [#11]
Are you compiling in debug mode? if so, what error does it give?

How much RAM is in your computer?
what version graphics driver are you using?


MGE(Posted 2008) [#12]
I dont have vista, but have you tried something like this, but is the app suspended during a lock?

Repeat
If AppSuspended()
DoPause()
End If
Cls
DrawImage(image,10,10)
Flip(1) ' always use flip 1!
Until KeyHit(KEY_ESCAPE)
'
Function DoPause()
While AppSuspended()
' Do something here
Wend
End Function


tonyg(Posted 2008) [#13]
What is the memory usage during the image load? Does the crash always occur on the same number or depending on when you lock?
When you say 'Crash' what exactly happens?
When you say 'Project' do you mean a Bmax project? Which IDE are you using? Does the problem occur with IDE version and .exe?
When did the problem start and how did you first notice it? What might have changed since you ran it?
How about posting the *real* code or .exe so people can be sure they are replicating the same thing?


Josepho(Posted 2008) [#14]
The bug was reported by a QA team while they were testing my project, it always happens when you block windows while a load script of graphics. When I say crash, i mean that the program terminates with an error. I cant post the exe of the game, but the code that i posted shows the same error when i block windows.

Perturbatio I dont think that my ram affects to the bug because the bug was reported by other people, i use the dx7 driver of blitzmax, the one who comes with the 1.30 version.

MGE, yup, when you press windows L the app is suspended, i donno if your code will help, but i know that the program crashes when its loading the images, i made that the program stop loading when it was suspended but if i do that, then shows an unexpected error that i thing that is that he try to draw an image that is loaded badly. I use flip without the 1, can this be the problem?

Tonyg the memory usage seems to not affect because the bug happens when i run my code with any kind of png. It always happens when i press windows L and im loading images, no matter which number or what kind of images. Im using the official IDE.


tonyg(Posted 2008) [#15]
When I say crash, i mean that the program terminates with an error.

but the code that i posted shows the same error when i block windows.

What is the error?
How is the loadimage loop involved and what is the significance of changing the loop count? What is the memory used after the loadimage loop? Does the problem occur with 1000 loadimage loop for any type of png used or will it change depending on image size?
If the example code is not a true reflection of your project then what processing does your project do?
What, exactly, happens when you press windows+L?
What are the machine specs and OS type of failing and working machines?


Josepho(Posted 2008) [#16]
This is the error "Create DX7 surface Failed"

The code of the project is not a loadimage loop, is a lot of loadimages of diferent images

image=LoadImage("image.png")
image2=LoadImage("image2.png")
image3=LoadImage("image3.png")
image4=LoadImage("image4.png")
image5=LoadImage("image5.png")
image6=LoadImage("image6.png")
image7=LoadImage("image7.png")
....

In the code that i posted it crashes with all the pngs that i have tried. My pc is a win vista, dual core with a geforce 8600 gt, the qa team reported that it happens in all windows, and i dont know what are the specs of the qa team computers. When you press windows+L the windows is bloqued and it seems that the game crashes when he tries to store the graphic in data, if you stop the loading and you try loading the data after the game shows lots of graphic glitches.


tonyg(Posted 2008) [#17]
I wonder if this is another symptom of the screensaver issue. That problem was fixed in 1.24 but maybe this particular symptom was overlooked.


Josepho(Posted 2008) [#18]
So, wich can be the solution? Waiting for a new bug fix? :S


tonyg(Posted 2008) [#19]
Probably. You might consider adding some debug statements to TD3D7GraphicsDriver createsurface method in d3d7graphics module to get the DX return code which might help narrow the problem down. Otherwise you should find some pattern in the failing machines, the smaller code which fails and post it as a bug.


MGE(Posted 2008) [#20]
"MGE, yup, when you press windows L the app is suspended, i donno if your code will help"

Try my code and see if it fixes your problem. You can't render if your app "loses the primary surface" which is what happens for instance in a full screen game and you minimize or go back to the desktop. You will get an error if you try to render. Internally Blitzmax will reset the surfaces, etc, etc. Never render while the app is in AppSuspend mode.


Tommo(Posted 2008) [#21]
It's because max2ddriver lose its d3d7device when you lock windows, so the max2d is using a null device when drawImage occurs.
The solution is use a setgraphics before rendering. Just like:
Local dx7gfx:TGraphics = Graphics (800, 600, 0, 0) 'get the TGraphics

Repeat
Until KeyHit(KEY_ESCAPE)

Global i:Int
Global image:timage

Repeat
i:+1
Print i

image = LoadImage("image.png")
Until i > 100

Repeat
SetGraphics(dx7gfx)  'SetGraphics will reset the device.
Cls
DrawImage(image, 10, 10)
Flip

Until KeyHit(KEY_ESCAPE)



MGE(Posted 2008) [#22]
I still think just checking for an app suspended will work.


Tommo(Posted 2008) [#23]
I tried suspend checking, under my XP, the example still crashed.
In Josepho's case, the problem happens when windows get locked while loading image, somehow driver lose its device(maybe the KILL_FOCUS event is not posted or not captured by bmx graphics driver, which is connected to driver's validating).


MGE(Posted 2008) [#24]
Thanks Tommo, that's very useful info. If Locking reports an app suspended, could you tie that into the image load section as well? Only loading if app is not suspended?


Josepho(Posted 2008) [#25]
I found a solution for the problem

Function DIsValid()
	TD3D7Max2DDriver(_max2dDriver).Flip(1)
	If TD3D7Max2DDriver(_max2dDriver).isvalid()
		Return True
	Else
		driverValid=False
		Return False
	EndIf
EndFunction


This function updates the driver state and tells me if the device is lost.
And this in the load script

Repeat

If Not(driverValid) Then TD3D7Max2DDriver(_max2dDriver).ResetD3DDevice(TMax2DGraphics.Current())

driverValid=True

If DIsValid() Then image=LoadImage("image.png")
If DIsValid() Then image=LoadImage("image2.png")
If DIsValid() Then image=LoadImage("image3.png")
If DIsValid() Then image=LoadImage("image4.png")
...

Until driverValid=True



The bug makes that the driver lose textures so i detect if the driver has been losed on the loading and i repeat the load if it needs. I reset the driver if the device has been lost too at the beginning of the load script.

This fix works perfect for me :D.


MGE(Posted 2008) [#26]
"so i detect if the driver has been losed on the loading and i repeat the load if it needs."

hmm... I'm not sure this is a stable solution because technically in a full screen game when the user presses the "Windows key" and it goes back to the desktop, the device is lost and Bmax automatically resets the device when switching back to full screen, all textures remain without having to load them again. Blitzmax uses managed textures so D3D pulls them from ram to vram as needed.

I still think the proper solution is to do "nothing" if the app detects it is suspended. Since locking does apparently return an app suspended flag this should be doable. I really don't think you should have to tap into the device lost flag, because you may actually be loading new surfaces (textures) without them being cleared from sram or vram.

At the least, if you stick with your current idea, you should remove ALL of the textures (set them to Null and do a GC() and load ALL of them again.

I would try something like this instead.....
counter = 0
totalimages=100
Repeat
 If AppSuspended()
  While AppSuspended()
    Delay(100)
   Wend
 EndIf
 counter = counter + 1
 image(counter)=LoadImage("image" + counter + ".png")
Until counter=totalimages