• Hello everyone,

    We're happy to announce that our forum is back online! We needed to take some time off to discuss and decide on how to handle sensitive topics in our community.

    The team has posted an in-depth comment regarding a recent incident and our stance on politics and sexuality in our forum. We also added a dedicated paragraph about this in the forum guidelines. This is part of our commitment to maintain a welcoming and inclusive environment for all our users. Your understanding and continued support in building a creative and respectful community are highly appreciated.

    Thank you, the CX Dev-Team

Implemented Warning, if LoadImage fails

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
821
I would like to see the LoadImage() function giving an error message, if the loading fails.

Changes in graphics.cxs
Code:
Function LoadImage:Image( path$,frameCount=1,flags=Image.DefaultFlags )
    Local surf:=device.LoadSurface( FixDataPath(path) )
    If surf
        Return (New Image).Init(surf, frameCount, flags)
    Else
        DebugLog "Error - Unable to load image: " + path   
    EndIf
       
End
Some beginners including myself stumbled upon this because of a typo and now I use this modification while setting up a new folder structure for my assets.
 
Thats something I have too; LoadImageSafe:Image(file:string)
except mine draws it off screen too, so that its loaded into Graphics memory ready for the game

Even though I have a function to test if a file is there, I'm not sure I would want an error in the Loadimage command. Without an error I could test for a NULL by design and then create an image. By adding an error check it removes functionality

In my latest project I load sounds in via a loop. If a sound file is not there I dont care, coz when I play the sounds I check for a NULL first.
 
Last edited:
Damn. Both make sense. But then Phil7's solution only throws an error in debug mode. I think that woukd be ok. What do you think @Rich ?
 
I think logging in Debug mode only would be fine.
 
can we have it so it only tests in debug too please? something like....
Code:
Local surf:=device.LoadSurface( FixDataPath(path) )
#if CONFIG="debug"
If surf
    Return (New Image).Init(surf, frameCount, flags)
Else
    DebugLog "Error - Unable to load image: " + path 
EndIf
#else
    Return (New Image).Init(surf, frameCount, flags)
#end
 
May I ask for what reason?
The if surf test was already there in the original version.
I think it breaks in Init() method if surf is Null because there is no Null testing in that method.
 
IMO..
In release mode, there should be no difference to the how the command works. Including doing a test. (I see this as overhead thats not required if no Log is output)
In debug, you are wanting to test and also accept an extra overhead and log if required.
 
just re-ead your post...

i see, i didnt realise the original had an "if surf" already there. I thought all error checking was added by yourself
Code:
Function LoadImage:Image( path$,frameCount=1,flags=Image.DefaultFlags )
    Local surf:=device.LoadSurface( FixDataPath(path) )
    If surf Return (New Image).Init( surf,frameCount,flags )
End

Ignore me.
 
Implemented on GitHub.
 
Back
Top Bottom