Gamestudio Links
Zorro Links
Newest Posts
Old models with Mixamo animations
by rayp
Yesterday at 21:21
rayp's old school fast zombie FPS project
by rayp
Yesterday at 21:10
Votes for future features
by AndrewAMD
Yesterday at 18:08
Series within loop
by tradingest
Yesterday at 15:24
TMF info
by AndrewAMD
Yesterday at 15:24
text outline breiter machen?
by tagimbul
Yesterday at 12:26
Reset vars
by tradingest
Yesterday at 00:40
AUM Magazine
Latest Screens
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Who's Online
5 registered (Akow, RealSerious3D, AndrewAMD, thewalruss, 1 invisible), 442 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
jiffdbf, jgtrader, Chefmac, BazGen, pallab1964
18079 Registered Users
Topic Options
Rate This Topic
#472483 - 04/30/18 18:21 file_length() incorrect values
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2210
Loc: Bavaria, Germany
file_length() seems to give incorrect results when it's used for larger files (a couple of megabytes or higher).

Here's a code example of how I used it:
Code:
var fhandle = file_open_read("test.mp3");
var Size = file_length(fhandle);
printf("size: %d", (int)Size);
file_close(fhandle);


What's interesting is that manually retrieving it using the engine's functions seems to give the same faulty results.
Code:
file_seek(fhandle, 0, 2); // seek to end
int Size = (int)file_seek(fhandle, 0, 4); // read position
file_seek(fhandle, 0, 1); // seek back to beginning

_________________________
POTATO-MAN saves the day! - Random

Top
#472484 - 04/30/18 18:57 Re: file_length() incorrect values [Re: Kartoffel]
Superku Offline
Senior Expert

Registered: 09/13/03
Posts: 6761
Loc: Kiel (Germany)
Those functions probably return real vars, right (instead of let's say int)? Then you've got your (file) limitations with the var range of around a million (bytes).
You will probably need to use Windows functions instead.
_________________________
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Superku The Game

Severely outdated footage: http://store.steampowered.com/app/407570

Top
#472485 - 04/30/18 19:06 Re: file_length() incorrect values [Re: Superku]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2210
Loc: Bavaria, Germany
Sounds like this is the case, thanks. Though, I'm confused that they decided to use var for those functions, as it doesn't make sense to get anything else than integers from them.
_________________________
POTATO-MAN saves the day! - Random

Top
#472690 - 05/14/18 19:31 Re: file_length() incorrect values [Re: Kartoffel]
Firoball Offline
Senior Expert

Registered: 09/10/03
Posts: 9835
Yes it is due to var limitations.
My guess is the functions already existed in WDL/C-Script, where there were only var and string.

I fixed this in a dirty way for end of file detection and otherwise avoided usage of file_seek and file_length as much as possible.

#define feof(f) (file_seek(f,1,4) == file_length(f))

if both functions deliver the identical (wrong) value, we've most likely reached end of file grin

Top
#472692 - 05/14/18 20:39 Re: file_length() incorrect values [Re: Firoball]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2210
Loc: Bavaria, Germany
I just ended up using the file-functions from stdio laugh
_________________________
POTATO-MAN saves the day! - Random

Top
#472712 - 05/15/18 16:54 Re: file_length() incorrect values [Re: Kartoffel]
Firoball Offline
Senior Expert

Registered: 09/10/03
Posts: 9835
Possibly the better idea.

Top


Moderator:  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de