newbie, error with my code
BlitzMax Forums/BlitzMax Beginners Area/newbie, error with my code| 
 | ||
| Hi ! The next code produce an error : ''unhandled exception:Unhandled memory exception error" but i don't understand why ! could you help me please ! Thanks ! 
Type Player
	Field x
	Function  Create:Player(FileName$)
		r:Player = New Player
		r.x = 1
		Return r
	End Function
	
End Type
Local p:Player
p = p.Create ("laser.png") ' <- error !
 | 
| 
 | ||
| hmm  it cant find laser.png (sounds like to me) I get the same error whenever it cant find a file im trying to load. | 
| 
 | ||
| OH yeah, are you loading teh image over and over again in a loop?  if you do that you'll cause a huuuge memory leak.. | 
| 
 | ||
| local p:player=new player matts right you should only load the image once, you can always pass a reference to the image for your create code... | 
| 
 | ||
| . | 
| 
 | ||
| p = player.Create ("laser.png") | 
| 
 | ||
| Eric, we already said that if he creates lasers (and loads the png file) everytime that he'll have a huuuuge memory leak!! Why help him break it? :P | 
| 
 | ||
| Well.. As I read the code there is no reference to loading the actual image.. I was only trying to get rid of the Error for him. :) | 
| 
 | ||
| Thanks ! with blitzplus you use copyimage. What's the method with bmax ? | 
| 
 | ||
| ummm, not sure if this is right... image:timage VariableName = loadimage "blah.blah" err is it variablename:timage = image:timage("blah.blah") hmmm cant tell off the top of my head. maybe it is ImageName:Timage = LoadImage:Timage ("blah.png") Then to draw it: DrawImage(ImageName,x,y) Sorry! I'm at work... :| | 
| 
 | ||
| According to the code-snippet, Eric has the correct fix. You can't do 
p = p.Create ("laser.png")
because the variable p has not be instantiated yet, and so is null. That is why you must use 
p = Player.Create("laser.png")
Everyone else appears to have been distracted by the fact that he was passing in a string for a file, which was not the cause of the error (even if, off topic, it wasn't a good idea in the future when the code was completed, to be loading an image for each new Player object) ;-) | 
| 
 | ||
| Thanks. I've modified the code now. This was an example. I agree that is a bad idea to use loadimage for each player ! |