I ran into a weird problem relating to scale, as in a lot of lines of code.
The basic problem is I didn’t pass a folder item to the method that scales the picture, and it failed.
I ran a very small test project with just a canvas, the line passing the code, and the method scaling.
It caught the nil object.
In my app with many many lines, it won’t catch the line.
Do you have any idea why this happens?
Here’s the Scale Picture method. Same code but no catch with scale.
try
'Var p2 as Picture
Var d as double
Var w, h, neww, newh as integer
w = PictureToScale.width
h = PictureToScale.height
d = min( Availablewidth/w,Availableheight/h ) // Calculate the factor with which to scale
neww = w*d // the new width of the picture
newh = h*d // the new height of the picture
Var p2 as Picture = new Picture( Availablewidth, Availableheight, PictureToScale.Depth )
p2.Graphics.DrawPicture PictureToScale, (Availablewidth-neww)\\2, (Availableheight-newh)\\2, neww, newh, 0, 0, w, h
return p2
Catch err As OutOfMemoryException
MessageBox("Insufficient memory to draw the picture!")
Return Nil
Catch err As NilObjectException
MessageBox("The Picture Cannot be Used Because of " + err.ErrorNumber.ToText)
Return Nil
Catch err As UnsupportedFormatException
MessageBox("The Picture Cannot be Used Because of " + err.ErrorNumber.ToText)
Return Nil
End Try