Memory Access Violation in Xeno Blaster

Blitz3D Forums/Blitz3D Programming/Memory Access Violation in Xeno Blaster

Tokra(Posted 2003) [#1]
Dear All I am getting a memory access violation in a game I am working on Called Xeno Blaster, I have posted the two moduals of code and can't sea any errors can some one look it over for me and check to sea if they can sea any thing please.

;Xeno Blaster By Darren Hunter 2003(c)
;-------------------------------------
;
SeedRnd (MilliSecs())

Include "XenoMusic.bb"
Include "XenoFont.bb"
Include "Xenokey.bb"
Include "XenoFX1.bb"
Include "XenoIntro.bb"
Include "paralax.bb"
Include "xenogame.bb"
Include "therocks.bb"

Global gamename
Global gamerezx
Global gamerezy
Global gfxstartup
Global gfxshutdown


gfxstartup=LoadSound("sfx\startup.wav")
PlaySound gfxstartup


gamerezx=800
gamerezy=600

;Set game name!!
AppTitle ("Xeno Blaster By Darren Hunter 2003(c)")


;Setup the graphics mode
Graphics gamerezx, gamerezy
SetBuffer BackBuffer()

;Music Verables
Global MainMusic


;Font Verables
Global bmpFont = LoadAnimImage("Font\Font.bmp",32,32,0,255)
Global bmpsmall = LoadAnimImage("Font\Font1.bmp",32,32,0,255)
Global arrow = LoadImage("gfx\arrow1.bmp")
Global arrowb = LoadImage("gfx\arrow2.bmp")
Global theship = LoadImage("gfx\ship.bmp")
Global theshot
Global sfxshot = LoadSound("sfx\shot1.wav")
Global rocka = LoadImage("gfx\rock1.bmp")
Global rockb = LoadImage("gfx\rock2.bmp")
Global rockc = LoadImage("gfx\rock3.bmp")
Global rockd = LoadImage("gfx\rock4.bmp")
Global rocke = LoadImage("gfx\rock5.bmp")


;Now put a mask on all the images that have been loaded
MaskImage bmpFont,0,0,0
MaskImage bmpsmall,0,0,0
MaskImage arrow,0,0,0
MaskImage arrowb,0,0,0
MaskImage theship,0,0,0
MaskImage rocka,0,0,0
MaskImage rockb,0,0,0
MaskImage rockc,0,0,0
MaskImage rockd,0,0,0
MaskImage rocke,0,0,0


;Game Verables
Global exitmenow
Global gamesmode

;Misc Verables
Global Headertitle$
Global sclen
Global starty
Global scrollerstart


;Fontmap verables!!!
Global fontchr
Global fontasc
Global mappos
Global asciival

Global sfontchr
Global sfontasc
Global smappos
Global sasciival

;Rock verables

;load in a backdrop image
Global backdrop=LoadImage("gfx\stars.bmp")

;initialize scroll variable to 0
Global scroll_y=0
Global arrowflip

;Menu verables
Global px
Global py
Global menuop

;Ship verables
Global theshipx
Global theshipy


;Setup the rock verables
Global rockx
Global rocky
Global rocktype
Global delrock
Global rockg
Global rgt
Global gfxtherock

;Set arrow position!
Global arrowpos

Type fmap
Field fontasc
Field fontchr
Field mappos
End Type


Type sfmap
Field sfontasc
Field sfontchr
Field smappos
End Type

Type thetheshot
Field theshotx
Field theshoty
Field theshot
Field killtheshot
End Type


Type rocks
Field rockx
Field rocky
Field rocktype
Field delrock
;Field rockg
Field gfxtherock
End Type


;Build the font map!
buildmap()

;Play the Music!!
PlayMusicNow()



gamesmode=0
exitmenow=0
;Now put the maingame loop in
While exitmenow=0
Cls
doparalax()
checkmusic()
checkkeypress()

If gamesmode=0 Then
setdefaults()
End If

;Ok here we will have to check the games mode to sea
;what mode wew are in to render / draw the write screen......
If gamesmode=1 Then
renderintro()
ElseIf gamesmode=2 Then

;Player Routeens
drawtheship()

;Astroid Routeens
darock()


End If

Flip
Wend

;Ok well if we are here that mean the ESC key has been presssed or
;quit has been selected on the menu!!!, which ever way we are going to have to close the program down!!!
gfxshutdown = LoadSound("sfx\shutdown.wav")
PlaySound gfxshutdown
dothefade()

End


Function setdefaults()
gamesmode=1
arrowpos =1
arrowflip =1
px = 215
py = 100
menuop=1
theshipx=400
theshipy=500
End Function

Above is the main code body

next is the rocks modual
;Containes all the code that is used to draw the rocks!!!



Function darock()

;This containes all the code to control the astroids!!
makedrock()

;Next move the rocks!!
movedrocks()

;Now draw the rocks!!
drawtherocks()

End Function


Function makedrock()
;this makes the astoroids!!
newrock.rocks = New rocks

If newrocks.rocks <> Null Then
rgt=1
newrocks.rocks\rockx=Rand(2,780)
newrocks.rocks\rocky=1
newrocks.rocks\rocktype=rgt
newrocks.rocks\delrock=0
If rgt=1 Then
;newrocks.rocks\rockg = LoadImage("gfx\rock1.bmp")
newrocks.rocks\gfxtherock = LoadImage("gfx\rock1.bmp")
End If
MaskImage newrocks.rocks\gfxtherock,0,0,0
End If

End Function




Function movedrocks()
;this moves the rock!!
For newrocks.rocks =Each rocks
newrocks.rocks\rocky=newrocks.rocks\rocky+20
Next

;this checks and deletes the rocks we dont need any more!!
For newrocks.rocks =Each rocks
If newrocks.rocks\rocky=newrocks.rocks\rocky >790 Then
newrocks.rocks\delrock=1
End If
Next

;Now delete therocks we dont need!!
For newrocks.rocks =Each rocks
If newrocks.rocks\delrock=1 Then
Delete newrocks.rocks
End If
Next
End Function

Function drawtherocks()
;this draws the rocks
For newrocks.rocks = Each rocks
DrawImage newrocks.rocks\gfxtherock,newrocks.rocks\rockx,newrocks.rocks\rocky
;drawimage rocka ,newrocks.rocks\rockx,newrocks.rocks\rocky
Next
End Function

For some reason I am getting an Error message every time i try to draw the dammed rocks.. I been looking over the code for the past 30 mins and cant sea what up with it..

if any one can help!!! please.

Remeber if your a lemming you will throw our self off a clif!!! (lol)


Gabriel(Posted 2003) [#2]
Turn Debug Mode on please. It'll save me reading all through your code.


Tokra(Posted 2003) [#3]
I found the problem Imissed an S of one of the types when i was typing it in a dammed typo.. I tryed the debug and it did not find ne thing..

strage or what!


puki(Posted 2003) [#4]
Yeh, Blitz Debug can, at times, be as much use as a chocolate frog in a furnace.


Tokra(Posted 2003) [#5]
Tell me about it, at least I am managing to track the problems now I have moved the project to BB3D insted of BB2D..

Well the compiler in bb3d seams a little better then the one in the old bb2D. Any ideas what would happen if I decided to try the project in b+!!