Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Mar 2018 18:16
The LoadImage command exits the application if the filename is invalid.
I believe the command should give the programmer the chance to handle the situation above.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Mar 2018 18:48
Perhaps you could check that the file exists yourself and handle it if you want to?


george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Mar 2018 19:38
Thank you for the suggetion, but this won't give an elegant solution. What will happen if the user select an existing but invalide file?
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Mar 2018 20:29
How is your user choosing an invalid image??

Are you using ShowChooseImageScreen() and if so it should only allow them to select .jpg and .png images which will load.

Do you have a specific corrupt file that causes a crash? Or are you trying to load a non supported format?
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Mar 2018 20:40
I am using ChooseRawFile() function.
I noticed this behaviour when accidentally I chose an .fbx file
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Mar 2018 20:53
Ahhh... You should check yourself then that the file extension is a jpg or apng then....

Alternatively....You should really use ShowChooseImageScreen() and GetChosenImage()

This will stop the user from selecting a file that isnt an image.
george++
AGK Tool Maker
16
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 5th Mar 2018 21:41 Edited at: 5th Mar 2018 21:42
Yes, the only solution would be extension check
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 5th Mar 2018 21:43
Quote: "I believe the command should give the programmer the chance to handle the situation above."


It is the job of the programmer to make sure he gets the chance



It is annoying that agk should exit upon encountering an invalid file, if its a project based app and the user is in the middle of editing a project file and has not saved in a while........ bummer!, and bad reps.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Mar 2018 21:53 Edited at: 5th Mar 2018 21:54
Surely its easier to use the filters built into the function??

Quote: "
function ChooseImageFile()

ret$=ChooseRawFile("*.jpg;*.png")
if ret$=""
exitfunction -1
// No file selected
else
Img = LoadImage(ret$)
endif

endfunction Img"


This only allows the correct extensions to be selected lol
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 5th Mar 2018 22:07
That wouldn't stop, in theory, a bad image file from killing it.

So instead, use CreateMemblockFromFile to load the image, then try using CreateImageFromMemblock.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 5th Mar 2018 22:18 Edited at: 5th Mar 2018 22:52
You also think it will just take a file loaded in memory (png or jpg) and decode it for you? You think CreateImageFromMemblock is more robust than LoadImage?

An image memblock has to be laid out correctly x,y and colour depth etc followed by RGBA data... So you would have to completely decode jpg's and pngs in AppGameKit basic into the memblock just to load these images.
We have a function to decode the file formats for us. (LOADIMAGE())

LoadImage doesnt exit or crash with a faulty png file...ive just tried it on a few sample filesand it simply doesn't load the file at all
Same for jpg too ...
These were perfectly good files originally with single byte changed in random positions

Besides....as george said...it was because he was trying to load an .fbx as an image that caused the problem.

Theres no need to resort to manually decoding image formats in memblocks when loadimage() works fine as long as its actually an image extension.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Mar 2018 22:27
Try SetErrorMode(0)
Remember that this applies to ALL errors
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 5th Mar 2018 23:57
Oops......wasn't really thinking that through, was getting things muddled in my head from other testing I Did.

As a side note, though not for choosing an image, but if you load an image, make a memblock, save that file you can load images the way I said, and they are 30-50 times faster due to zero compression. They are also larger, obviously, but actually on smaller images not as much as you'd think. You can mix the methods to display, For example, menus super quickly.
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 6th Mar 2018 00:18 Edited at: 6th Mar 2018 00:29
You can just save a PNG as uncompressed (this is normal) and load it with LoadImage () and its just as fast (if not faster) without the use of memblocks. lol No decompressing at all.

https://en.wikipedia.org/wiki/Portable_Network_Graphics its the 32bit RGBA data in the IDAT chunk which is uncompressed image data (if saved uncompressed)- same as what you would find in the memblock

Its jpg that is slow (pretty complex algorithm) but saves you loads of disk space. Take your pick - disk space or access speed.

Personally, I like both, so id just pre load images - fast to show them pretty much instantly as they are already on the graphics card memory and they can still be small on disk (for quick downloads). Most machines are 4gig+ memory so no worries with memory space having a few extra images in anyway.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 6th Mar 2018 10:59
Except mobiles, obviously.

I'd like to see some tests with PNGs as I used them in my testing and they were faster than jpegs but still hugely slower than memblocks.....and that's PNGs saved in Photoshop. May be an option I was missing though. The other advantage is you can "stream" a memblock, though for large ones this is actually slow.

Can you tell I like memblocks? Lol
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 6th Mar 2018 11:02
https://forum.thegamecreators.com/thread/219750
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 6th Mar 2018 11:13
Quote: "Except mobiles, obviously. "
Yes...funny as im replying on my samsung s7 with 4gig of memory...lol (But yes, ill concede that most mobiles dont have that much. give it a year...they will all have twice that...technology woohoo)
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 6th Mar 2018 11:35
I'm on an S8+, so I'm the same.....technically speaking my phone is significantly more powerful than my laptop!!!

Login to post a reply

Server time is: 2024-03-28 20:43:03
Your offset time is: 2024-03-28 20:43:03