TMSafeLoadImage
BlitzMax Forums/BlitzMax Programming/TMSafeLoadImage
| ||
I have this functionFunction TMSafeLoadImage:TImage(Path:String,flag:Int=-1) If FileType(Path) Local image:TImage=LoadImage(path,flag) If image Return image Else Notify "SafeLoadImage Error: File "+Path+" exists but does not load" EndIf Else Notify "SafeLoadImage Error: File "+Path+" does not exist" End End If End Function It will work fine with a normal file reference but fails with Incbin:: Does this occur for you as well... anyone know why it would? |
| ||
FileType only handles files on the file system. You'll have to do something else for incbinned files. |
| ||
Function TMSafeLoadImage:TImage(Path:String,flag:Int=-1) local stream:TStream=ReadStream(path) If stream Local image:TImage=LoadImage(stream,flag) stream.close() If image Return image Else Notify "SafeLoadImage Error: File "+Path+" exists but does not load" EndIf Else Notify "SafeLoadImage Error: File "+Path+" does not exist" End End If End Function Try this. |
| ||
Oh talk about tunnel vision.. night time!Function TMSafeLoadImage:TImage(Path:String,flag:Int=-1) If Path.Contains("Incbin::") Return LoadImage(Path,flag) If FileType(Path) Local image:TImage=LoadImage(path,flag) If image Return image Else Notify "SafeLoadImage Error: File "+Path+" exists but does not load" EndIf Else Notify "SafeLoadImage Error: File "+Path+" does not exist" End End If End Function Thanks! |
| ||
Shouldn't you still check "If Image" ? And Tommo's idea of using TStream I would expand to have TMSafeLoadImage() accept Object as a param, which could then convert to TStream/String internally. But if the function is a private thing, then I guess it doesn't matter? |
| ||
If you get the Path as an object instead of as a string it should work. |
| ||
Shouldn't you still check "If Image" ? Quite right... I've been running on about 3-4 hours sleep the last few days... got a good 6 in last night so I'm feeling a little more aware ;) And Tommo's idea of using TStream I would expand to have TMSafeLoadImage() accept Object as a param, which could then convert to TStream/String internally. indeed.... But if the function is a private thing, then I guess it doesn't matter? No its one of the documented TilMmax functions. I found it handy when I used a similar approach in Santas Slay. I guess the zip extracted flat and the game notified of the problem... it was when we were trying to get it running on vista.. which I don't think ever worked (earlier B3D)... I've lost the source (one month comp.. HD Controller crash.. both mirrors killed). If you get the Path as an object instead of as a string it should work. I like that idea |
| ||
I like that idea Of course you do.. I said it first ;-) |