sareph / th9x

Automatically exported from code.google.com/p/th9x
Other
0 stars 0 forks source link

Model size limited to 255 bytes #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hopefully this will save you the headache I had:

When the compressed model size rises above 255 bytes the data gets corrupted.   
This is because read() uses bytes and not words.   The fix is really easy:

In file.cpp:
uint8_t EFile::read(uint8_t*buf,uint8_t i_len){
  uint8_t len = eeFs.files[m_fileId].size - m_pos;  //<- this is the problem row

Should be:

uint8_t EFile::read(uint8_t*buf,uint16_t i_len){
  uint16_t len = eeFs.files[m_fileId].size - m_pos; //<- Problem fixed!

In file.h:
uint8_t read(uint8_t*buf,uint8_t i_len);

Should be:
uint8_t read(uint8_t*buf,uint16_t i_len);

Original issue reported on code.google.com by erezra...@gmail.com on 13 Sep 2010 at 5:24

GoogleCodeExporter commented 9 years ago
exactly this is changed in r144 (merge from er9x  :-))  ).
The original implementation was not thought to handle larger files.

Original comment by th...@t-online.de on 13 Sep 2010 at 6:44

GoogleCodeExporter commented 9 years ago
Yeah, I saw :)  (and I'm flattered).

But the issue concerns the function EFile::read().  In r144 it's still using 8 
bytes.
This caused me a very big headache.  The compiler doesn't tell you anything is 
wrong and the struct can go over 255 bytes but as soon as the compressed file 
size goes over 255 bytes you still have a problem.

The function uses a byte when reading.   When the compressed size is over 255 
bytes then the line:  uint8_t len = eeFs.files[m_fileId].size - m_pos;  
defaults to a byte and the information is written to the beginning of the 
struct.

Original comment by erezra...@gmail.com on 13 Sep 2010 at 7:50

GoogleCodeExporter commented 9 years ago
ok
as i see you should have problems with read.
If size gets larger than 255, then you can read only the modulo 256 size.
e.g. if size is 260 then you can read the first 4 bytes.
I reanimated the TEST section in the file.cpp and extended the test to a 300 
Bytes file. -> now it works.

Original comment by th...@t-online.de on 13 Sep 2010 at 9:34