How to Open image file from Windows PC in simulator?

Ah! Okay this works every time!

Well Done and Thank You :slight_smile:

By the way, why is this?

(cc @kisvegabor)

It looks like there was a mixup between the open and fopen functions.

TL;DR open will return -1 if opening the file failed, while fopen will return NULL. However, the failure check seems to have mixed them up.


The reason you got away with this in rare cases is because of the cast to a signed integer. Let’s assume for our purposes that all pointers and integers are 32-bit.

Under normal conditions, fopen will return a pointer to a stream. The maximum signed 32-bit integer is 0x7FFFFFFF. Let’s say that fopen returned a pointer that was greater than that value (e.g. 0x80000000).

If the value 0x80000000 were to be forced into a 32-bit signed integer, it would equal the smallest possible signed integer (roughly negative two billion). Since that is a negative number, the check would fail even though the file was opened successfully.


In the meantime, I’ve fixed the issue here: https://github.com/littlevgl/lv_examples/commit/2b3c4004cb1d8060f6a04172b038131cccd89b07

Thank you for finding it! I am still surprised that no other implementations of fopen have ever caused this issue.

1 Like

Wow, nice catch!

Thank you for the fix!