gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Libfat / devkitpro 20 problem with fwrite(),fseek()

#119315 - Diddl - Wed Feb 21, 2007 9:01 pm

below there are binaries and sources to demonstrate the problem with current libfat. the problem appears on R4, M3 lite and SuperCard lite in the same manner.

please patch binaries with your DLDI driver and test it yourself.


Not working sample: source, binary

Working sample: source, binary


the only difference in source are this lines:
Code:
for(i = 0; i <= ANZ_BLOCKS; ++i)

Code:
for(i = ANZ_BLOCKS; i >= 0; --i)



My suspicion is, the error occurs if the last operations are

  • a fseek() behind the end of file
  • a write access - fwrite() or fputs()
  • a fclose()


The interesting part is, the file is damaged! neither the NDS nor my PC can read this file. Windows says
Code:
cannot copy the source file.


Last edited by Diddl on Wed Feb 21, 2007 10:50 pm; edited 1 time in total

#119324 - 0xtob - Wed Feb 21, 2007 10:30 pm

I can confirm the problem (tested on SC Lite).

Both of your source links point to the same file, the second link should point to http://web3.vs2066076.netfabrik.de/nds/test_libfat_src_2.rar.

I hope you are aware that both of your loops actually iterate ANZ_BLOCKS + 1 times.
_________________
http://blog.dev-scene.com/0xtob | http://nitrotracker.tobw.net | http://dsmi.tobw.net

#119329 - Diddl - Wed Feb 21, 2007 10:53 pm

0xtob wrote:
Both of your source links point to the same file, the second link should point to http://web3.vs2066076.netfabrik.de/nds/test_libfat_src_2.rar.


thanks! I've corrected this ...

0xtob wrote:
I hope you are aware that both of your loops actually iterate ANZ_BLOCKS + 1 times.


this is ok. blocks below 259 are 256 bytes blocks. the last on is only a simple text. I want to to the fat test with a odd number of bytes ...

#119419 - Payk - Thu Feb 22, 2007 9:49 pm

Ok have to report stuff too.

R4 does hang when my game start rendering part. I am pretty sure it has loaded all stuff and tries to render first frame. I guess that it failed to load models right.(could be another fseek issue, but device dependendly)

DS-Xtreme loads first map fine but then a "out of memory" (malloc returns NULL) occures.
If i deactivate sound-stuff it works absolutly fine. The reason could be wrong filesizes returned by dldi (my texture/model loading functions dont need to know filesize but the music loader needs to know) or some arm7<>arm9 issue. For example that ds-xtreme maight load homebrew stuff a bit wrong. But would just be since r20.

Sorry for that short report. I will do some bugtracking at this weekend.
It would be cool if more ppl could bring some reports here or could help a bit.
Thanx

#119465 - chishm - Fri Feb 23, 2007 6:33 am

I traced the bug down for the seek problem. It has to do with seeking to the exact end of a file. I'll fix it when I can.

Payk:
If you can, load your game via WMB, but patched for the R4 or DS-X (whichever one you're testing). If it works fine then the problem is with the menu. Also make sure to use the DS-X DLDI file from my site. The one on the DS-X site has bugs.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#119700 - chishm - Sun Feb 25, 2007 11:35 am

Seek then write bug is fixed in CVS now.
_________________
http://chishm.drunkencoders.com
http://dldi.drunkencoders.com

#119717 - Diddl - Sun Feb 25, 2007 3:29 pm

thank you Chishm. you are great!

#119730 - Payk - Sun Feb 25, 2007 5:55 pm

Hey, yeah wmb helped for the r4. Thanx.
But the DS-Xtreme DLDI from you site was that one which i was using.
Maybe its not a fatbug at all. Could be some other stuff similar to the r4 one.
But thanx for infos ;)