LoadSound doesnt Return Null if path is invalid
Monkey Forums/Monkey Bug Reports/LoadSound doesnt Return Null if path is invalid
| ||
When running this code: [monkeycode]Strict Import mojo Function Main:Int() New MyGame() Return 0 End Class MyGame Extends App Field snd:Sound Method OnCreate:Int() SetUpdateRate(30) snd = LoadSound("itdoesntmatter") If snd = Null Then Error "snd is null!" Return 0 End Method OnUpdate:Int() Return 0 End Method OnRender:Int() Cls PlaySound(snd) Return 0 End End[/monkeycode] I would have thought the Error would be raised, but it looks like LoadSound doesnt return a null like LoadImage. |
| ||
I agree it would be better if the return value was null for an invalid path. Or something like the (undocumented) Image.Loaded() method. I switched most of my resources to async loading and I feel for async it's even more important to check if a resources is actually loaded. With images I do something like [monkeycode] Method OnLoadImageComplete:Void(_image:Image, path$, source:IAsyncEventSource) image = _image If image = null Then Print("WARNING: could not load async image resource " + path) End [/monkeycode] The same for If sound = null doesn't work because it sound is never null at that point in the programme code. |