# HG changeset patch # User sheepluva # Date 1402337651 -7200 # Node ID 25155aaede77a79d07f8fe8ea8527cecf8c313ab # Parent c85d241d9cc9c7141acefbc455ae5f328fd1ae91 clean up image loading a bit. gets rid of useless "Passed NULL data source" or PhysFS file not found errors diff -r c85d241d9cc9 -r 25155aaede77 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Sat Jun 07 16:25:40 2014 +0200 +++ b/hedgewars/uStore.pas Mon Jun 09 20:14:11 2014 +0200 @@ -599,17 +599,40 @@ function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; var tmpsurf: PSDL_Surface; s: shortstring; + rwops: PSDL_RWops; begin LoadImage:= nil; WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] '); s:= filename + '.png'; - tmpsurf:= IMG_Load_RW(rwopsOpenRead(s), true); + + rwops:= nil; + tmpsurf:= nil; + if pfsExists(s) then + begin + // get data source + rwops:= rwopsOpenRead(s); + + // load image with SDL (with freesrc param set to true) + if rwops <> nil then + tmpsurf:= IMG_Load_RW(rwops, true); + end; + + // loading failed if tmpsurf = nil then begin + + // anounce that loading failed OutError(msgFailed, false); - SDLTry(false, (imageFlags and ifCritical) <> 0); + + // output sdl error if loading failed when data source was available + if rwops <> nil then + begin + SDLTry(false, (imageFlags and ifCritical) <> 0); + // rwops was already freed by IMG_Load_RW + rwops:= nil; + end; exit; end;