Image does not exist ERROR

Blitz3D Forums/Blitz3D Programming/Image does not exist ERROR

Fernhout(Posted 2015) [#1]
the following code give me sometime the error Images does not exist:



I know that the above code is wrong but sometimes the computer is running this always at first time starting. When i start the program after canseling it first time. Some times it wil start with no problem but most of the times i got the error images does not exist.

I would expect i wil get the error always. Cause i init the screen after i did init the graphic of the leftcornerUp.
What is wrong in the compiled program so that is run always on the first time.


Floyd(Posted 2015) [#2]
Every time the Graphics command is executed the entire graphics system is reinitialized.

In your case that means LeftCornerDown is lost.

I don't know why it would ever work, should always be an error.


Fernhout(Posted 2015) [#3]
Floyd
You are right. But my first question is therfore why wil it always work on a first run. In a way. If i Start the computer and run de compiled of just compiling the source code and run it. it always works good. If i run the whole program no problem.

second point when i run later on the already compiled program is wil give me 99% of the time a error of the image.
Do i recompil de code the the error rate is going down to 65% in the error.

But When i run the program first time. And close it, wait for at least an half hour. then recompile again. 98% of the time no error.

In all cases its odd thart the program is runnal anyway. An error is an error and not a somting like an error.

As if Blitz3D would say how do i feel myself. O i feel fine so in give the player its way and run the program anyway. The next time its feeling bad and give the error.

I put this here because i run against it when i put the code on the wrong way. First i couldnot understand it the after 3 hours of looking at the code i did see it.

So now its het the why this happend.


Floyd(Posted 2015) [#4]
I can only guess what is happening.

Maybe the image is set up in graphics memory, then Graphics starts everything again. If the memory used by the image has not been reused then perhaps you can still use it. I'm thinking of this as being like a deleted file on a disk drive, which can be recovered if it hasn't be overwritten.

That's just speculation, I don't really know.


Matty(Posted 2015) [#5]
Given you never do anything with LeftCornerDown it should not give an error at all.

In fact it should never give an error - if the file exists in the correct location.

I personally think it is more likely that the error is that you are running the code from within the 'tmp' folder on first writing it in which case the file is not found, but that if you save it in the correct location and run it from there it will work perfectly...as long as the file actually exists.

The Graphics command does clear the graphics but you never call any of the graphics that were created before it anyway so it is a moot point.


TomToad(Posted 2015) [#6]
Problem is that you are using LeftCornerUp to grab the image, but you created the image in LeftCornerDown.

LeftCornerUp is pointing to a random chunk of memory, so it might work or might not depending on exactly where it points. If it is pointing to "valid" memory, then GrabImage succeeds and you can draw the image. If it does not point to "valid" memory, then GrabImage fails and you get an error when trying to draw.

I put "valid" in quotes because the system sees it as valid, i.e. it points to what looks like a valid image header, but most likely it is corrupting the program or variable heap in memory which would show up in larger programs.


Matty(Posted 2015) [#7]
Also CombinedWindow is named CombineWindow elsewhere.


Fernhout(Posted 2015) [#8]
Oke i see the point i did write down. But in my code i used more varables. All of them used a corner.

The file is not made in a tmp folder. I wun win 8.1 and its not allow me to compile if i not already saved the file to some loction the has write enabled.

I had compiled the program a sort file, and always the first run. On whetever location. I get the right graphics on the right location.
Second run gives 98% of the time an error.

E.G. I start a motor and alway its run at once. But as soon i turn of the motor i almost never could restart the motor.

Its not a very good example but i think i make my point.

After a little research and a couple of memory dumps, i figure it out.

The compiled program create a piece of memory when i ask for creating an image. Then the variable gets a heash adres from where the real image is. This adres is not cleared. When i create a new graphic mode. The adres it self get overwritten when the graphics is created. But only if there is a chunk of memory is free at that point.

When the program start for the first time there is enough memory left to adres a complete new part of the memory. Windows is given this to the program. So as soon as the image mem is requested and afthe that the Graphics of the screen. They lay after each other. The pointing is now illigal but still there. The program is finding information and can not give an error.

When the program is terminated windows is not giving this peice of memory free. So when i restart the file a new piece of memeory is allocated. The requeste image memory and the graphics memory is to close to eachother so the beginning of the screen information is overwritting the information of the image data. Due to a piece of protected memory the called information is not given. Its return a 0. Then the error kick in.

Thats why this normaly works whet windows did not run the progrma for a couple of minutes. Then the memory is freed up. Between the HD data and the real memory.

This in also only working if the program in not to big. To much graphics and music/sound will screw this up. Windows is swapping memeory so the error can come faster even at the start of the program.

In my test it wend so far that i got other graphics on my screen.

But thanks guy for the info.

bart.


_PJ_(Posted 2015) [#9]
The code above fails for many reasons due to syntax errors and what appear to be fairly straightforward errors in programming. Such as LeftCornerUp never being populated but then called as an image, that there are three similar but not identical variables used which seem confused versions of CombinedWindowed, that the GrabImage as LeftCornerUp not grabbed from the Left Upper Corner of the buffer...

Whilst I don't believe these are actually to what Fernhout is trying to point to as the issue, they may indicate a possible reason why other errors occur.

A cleaner code which highlights the potential problem is here:
Global CombinedWindows
Global LeftCornerUp
Global LeftCornerDown

;Set image preparation
LeftCornerUp 	= CreateImage(10,10)
LeftCornerDown 	= CreateImage(10,10)

Graphics 640,480,32,2

SetBuffer BackBuffer()

;Load the graphics
CombinedWindows	= LoadImage ("Graphics\Windowed.bmp")

SetBuffer ImageBuffer(CombinedWindows)

GrabImage LeftCornerUp,0,0
GrabImage LeftCornerDown,0,ImageHeight(CombinedWindows)-10

SetBuffer BackBuffer()

DrawImage LeftCornerUp,0,0
Flip 
WaitKey()
End



This will fail and I believe highlights Fernhout' real problem.
However, as Floyd already pointed out, this is due to the placement of the Graphics command AFTER The CreateImage - It seems like this mention by Floyd was somewhat misunderstood or ignored.

The fact that it may SOMETIMES work is not an indication that it ought to always work, and instead highlights that there's a fault. The actual "WHY" isn't so important as how to fix it.

The following works perfectly every time:
Global CombinedWindows
Global LeftCornerUp
Global LeftCornerDown


Graphics 640,480,32,2

SetBuffer BackBuffer()

;Set image preparation
LeftCornerUp 	= CreateImage(10,10)
LeftCornerDown 	= CreateImage(10,10)


;Load the graphics
CombinedWindows	= LoadImage ("Graphics\Windowed.bmp")

SetBuffer ImageBuffer(CombinedWindows)

GrabImage LeftCornerUp,0,0
GrabImage LeftCornerDown,0,ImageHeight(CombinedWindows)-10

SetBuffer BackBuffer()

DrawImage LeftCornerUp,0,0
Flip 
WaitKey()
End



Fernhout(Posted 2015) [#10]
_PJ_

Sorry but i realy do want to know WHY. I do know how to program on a clean way.

I also have to program and redo the graphics when i switch between windows and full screen.

But The WHY the compiled program runs always the firsttime good and almost neven a second time. WHAT is the differend to that.

I already have explained it. By grabbing some memory and look if its overwitten of reused by the program.

Becaus windows is very sloppy with its memory the first run always work cause the memory is as one chunk. And when windows find time the second time will work to after the cleanup by windows.
The pointers to the memory almost neven chainged in the program.that why it work. due to the right information of that piece of memory.

And to get to the point of Floyd in my opinion he has a point. Its supposed to make alway an error and not work one time.


Another point for me why is the compiler not seeing this. ITs detecting te graphics mode and there is premade graphics memory ready.
But that is a complete differend story.

Its my job to try to find the why of something so when i got to this problem i thouth let give the people a change to explain why.