• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Implemented Warning, if LoadImage fails

Phil7

Moderator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
886
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.
 
Back
Top Bottom