file problems

BlitzMax Forums/BlitzMax Beginners Area/file problems

Ghost Dancer(Posted 2006) [#1]
I'm just putting the finishing touches to my game and somehow I have introduced a very strange bug.

After playing the game for a short time, all file access fails (e.g. loading an image, saving a data file). Does anyone know why this could happen? Why would a LoadImage or WriteFile fail when they worked previously within the same game session? What could I have done to prevent this from working?

Posting code is difficult as I'm not sure exactly where the problem occurs, only that it does. It just seems like something is causing all file access to fail but I have no idea as to what would cause this.

Sorry if this is a bit vague but I am hoping there is some obvious reason as to why this happening - I've spent hours trying to fix it and it's driving me nuts! If anyone can shed some light on this I would be eternally grateful!


H&K(Posted 2006) [#2]
It is possible that you have filled the video ram? And as such can no longer load imagess


Ghost Dancer(Posted 2006) [#3]
Good thought but I don't think so - there are not many images and I have a 256MB card. Plus that wouldn't explain why I can no longer write the data file either!


SculptureOfSoul(Posted 2006) [#4]
I think there is a limit to the number of file streams you can have open at any time. Make sure you use CloseStream() whenever you want to close a file.

No idea if that will fix it or not, but it's all I've got ;).


Ghost Dancer(Posted 2006) [#5]
Thanks fir the suggestino but all streams are closed.

I've done some more testing and have the following:

dataFile = WriteFile(saveFile$)

If dataFile Then
	'code here
	
	
	CloseFile(dataFile)
Else
	Local tempImg:TImage = LoadImage("gfx\test.png")
	If  tempImg = Null Then Print "no image"
	RuntimeError "ERROR: Could not write save file " + saveFile$
End If



Both the "no image" & runtime message are output. So it can not open the image file, and can not write to the save file. Note that both the savefile and image were previously loaded before this code was run so the files definately exist and have been accessed previously.

The error does not always occur so sometimes the savefile is updated and images are loaded - very odd. I've just realised it's Friday 13th, so maybe I'll leave it until tomorrow and have another crack at it ;-)


SculptureOfSoul(Posted 2006) [#6]
One thing I'd recommend doing is doing a FlushStream( datafile ) after you make your writes to your data file. I've found that in some cases this is necessary (see my thread titled "Bug, Perhaps?" for more details on that.)

The graphics loading thing is really weird. I'm not normally superstitious but today HAS been weird. I already managed to break a large glass bowl at work in a freak situation. And I've had some code go weird on me as well.


Ghost Dancer(Posted 2006) [#7]
I finally found the problem - the save file was not always being closed, so programmer error, he he.

Thanks for your help though!