'Memory Access Violation"

Blitz3D Forums/Blitz3D Beginners Area/'Memory Access Violation"

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

I keep getting this error message when running my compiled code saying "Memory Access Violation". It happens in the first second of the program being run. Why is this happening? Here is my code:

; map editor

Graphics3D 800, 600, 32, 2

SetBuffer BackBuffer()

AppTitle("Map Editor v1.0")

Global t_menu = LoadImage("graphics\t_menu.bmp")
	MaskImage t_menu, 0, 255, 0
Global b_menu = LoadImage("graphics\b_menu2.bmp")
	MaskImage b_menu, 0, 255, 0
Global file = LoadImage("graphics\file.bmp")
	MaskImage file, 255, 255, 0
Global quit = LoadImage("graphics\quit.bmp")
	MaskImage quit, 255, 255, 0
Global n = LoadImage("graphics\n.bmp")
	MaskImage n, 255,255,255
Global p = LoadImage("graphics\p.bmp")
	MaskImage p, 255, 255, 255
Global tiles = LoadAnimImage("\Tiles\Terrains\terrain.bmp",64,64,0,5)
	MaskImage tiles, 255, 255, 255
Global pointer = LoadImage("graphics\mouse.bmp")

Dim map(32, 24)

Global currenttile#=1
Global mapx# = 32
Global mapy# = 24

Global gridon# = 0

Const erase#=0


While Not KeyHit(1)

	; pointer coordinates

	p_x# = MouseX()
	p_y# = MouseY()
	
	Cls
	
	; Button setup
	If ImagesOverlap(pointer, p_x#, p_y#, n, 101, 582) Then buttonon(n)
	If ImagesOverlap(pointer, p_x#, p_y#, n, 101, 582) And MouseHit(1) Then currenttile=currenttile+1
	If currenttile > 4 Then currenttile = 1	
	If Not ImagesOverlap(pointer, p_x#, p_y#, n, 101, 582) Then buttonoff(n)
	
	If ImagesOverlap(pointer, p_x#, p_y#, p, 20, 582) Then button2on(p)
	If ImagesOverlap(pointer, p_x#, p_y#, p, 20, 582) And MouseHit(1) Then currenttile=currenttile-1
	If currenttile < 0 Then currenttile = 4
	If Not ImagesOverlap(pointer, p_x#, p_y#, p, 20, 582) Then button2off(p)
	
	If ImagesOverlap(pointer, p_x#, p_y#, quit, 73, 0) And MouseDown(1) Then End
	
	update()
	controls()

	Text 0,18,"X: "+MouseX()
	Text 0,28,"Y: "+MouseY()
	Text 0,38,"Press the 'G' key to enable the grid."
	
	Flip

Wend
End

; button mouse-over effects

Function buttonon(n)

	FreeImage n
	n = LoadImage("Graphics\n2.bmp")

End Function

Function buttonoff(n)

	FreeImage n
	n = LoadImage("graphics\n.bmp")

End Function

Function button2on(p)

	FreeImage p
	p = LoadImage("graphics\p2.bmp")
	
End Function

Function button2off(p)

	FreeImage p
	p = LoadImage("graphics\p.bmp")

End Function

; update

Function update()

For x#=0 To mapx#
	For y#=0 To mapy#
		DrawImage tiles, x#*64, y#*64,map(x#, y#)
	Next
Next

	DrawImage t_menu, 0, 0
	DrawImage file, 0, 0
	DrawImage quit, 73, 0
	DrawImage b_menu, 0, 540
	DrawImage n, 101, 582 ; next button
	DrawImage p, 20, 582 ; previous button
	DrawImage tiles, 38, 540, currenttile

End Function

Function controls()

	tile_x# = MouseX()/64
	tile_y# = MouseY()/64

	DrawImage pointer, p_x, p_y ; mouse

	If MouseDown(1) And tile_x# < 32 And tile_y# < 24 Then map(tile_x#, tile_y#)=currenttile#
	If MouseDown(2) And tile_x# < 32 And tile_y# < 24 Then map(tile_x#, tile_y#)=0
	
	If KeyHit(34) Then gridon# = +1
	
	grid()
	
	
End Function

Function grid()

If gridon# = 1
If gridon# > 1 Then gridon = 0

For x# = 0 To mapx#
	For y# = 0 To mapy#
		Rect x#*64, y#*64, 64, 64, 0
	Next
Next

EndIf

End Function