getting "Image does not exist" with valid image

Blitz3D Forums/Blitz3D Beginners Area/getting "Image does not exist" with valid image

NeuralizR(Posted 2004) [#1]
Yes, I realize this code is missing a lot of things to be remotely functional or perform reasonably. I've removed anything that didn't seem relevant to the problem.

So in the draw_map() function, it's giving an "Image does not exist" error. I added some extra code to put the array value in a variable first so I could see what the value was in debug mode and it appears to be an image pointer. Also, there are a few global values for the 3 handles of the images created that went into the array, so you can see that the image handle value being pulled from the array is one of the value handles.

I can't figure out why, even though the value is a valid image handle, the DrawImage function is throwing an error saying that it's not...

Global testvalue0
Global testvalue1
Global testvalue2

Const screen_width = 1152
Const screen_height = 864
Const screen_depth = 32
Const map_width = 512
Const map_height = 512
Const map_layers = 1
Const num_tiles = 255

Dim tiles(num_tiles)
Dim map(map_width,map_height,map_layers)

init_tiles()
init_map()
	
Graphics(1152,864,32,0)
SetBuffer(BackBuffer())

While(Not KeyHit(1))
	ClsColor(58,110,165)
	Cls
	draw_map()
	Flip(False)
Wend

End

Function init_tiles()
	tiles(0) = CreateImage(32,32)
	testvalue0 = tiles(0)
	tiles(1) = CreateImage(32,32)
	testvalue1 = tiles(1)
	tiles(2) = CreateImage(32,32)
	testvalue2 = tiles(2)
End Function

Function init_map()
	For x = 0 To screenwidth-1
		For y = 0 To screenheight-1
			map(x,y,0) = Int(Rnd(0,2))
		Next
	Next
End Function

Function draw_map()
	For x = 0 To map_width-1
		For y = 0 To map_width-1
			tile_image = tiles(map(x,y,0))
			DrawImage(tile_image,x*32,y*32)
		Next
	Next
End Function



NeuralizR(Posted 2004) [#2]
You should be able to just copy/paste this code and run it btw, if you want to see the error and debug info. Though you might want to set the mapwidth and height to say 32 each. >.> Sorry about that.


GfK(Posted 2004) [#3]
You're initialising the images, then setting the graphics mode (which frees all images).

Change this:
init_tiles()
init_map()
	
Graphics(1152,864,32,0)
SetBuffer(BackBuffer())
To this:
Graphics(1152,864,32,0)
init_tiles()
init_map()
SetBuffer(BackBuffer())

There's also a problem with your Draw_Map function. The second line should be:
For y = 0 To map_height-1



NeuralizR(Posted 2004) [#4]
Ooops... lol

Great.... now that you mention it, it's completely obvious. :)

Thanks for the catch on the map_width vs map_height :P

I obviously haven't gotten far enough into making this work for that to come up yet. :)


NeuralizR(Posted 2004) [#5]
Also a few other obvious problems, like initializing the map to the screen height and width....


wizzlefish(Posted 2004) [#6]
I ALWAYS get this message....turns out I haven't saved my work.


BlitzSupport(Posted 2004) [#7]

I ALWAYS get this message....turns out I haven't saved my work.


That's one I'll have to remember -- Blitz will be looking for images in the Blitz3D\tmp folder if you haven't actually saved your work anywhere.


jfk EO-11110(Posted 2004) [#8]
not only images but all files if their path is relative, if i remember correctly.


BlitzSupport(Posted 2004) [#9]
Yep...