Problems with Viewport #860
-
Hi! First of all, it's great to have a forum for discussions about problems how to use this lib in the right way. In my project, I apply a viewport on a TFT_eSPI object called tft. |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 5 replies
-
This may be a bug in the library or sketch. Please post a complete example sketch that demonstrates the problem. |
Beta Was this translation helpful? Give feedback.
-
Well, I try another approach using sprites. I noticed I could do what I want using sprites only and save some memory. But it's very strange, for some reason, if one of the three sprites is modified, they are all modified. This seems to be a bug in your library. It seems like they're pointing to the same data, but they intended to be copies which should contain different data. |
Beta Was this translation helpful? Give feedback.
-
I do not have the time to look in detail at users own projects. A quick look at this sketch line makes me think all the instance array is initialised to the same value (object reference), so then only one sprite will be created, not 3:
The other observation is that you are trying to create 3 very large sprites, this will not be possible unless your board has PSRAM fitted. |
Beta Was this translation helpful? Give feedback.
-
I think you have printed out the addresses of the array elements which are bound to be different. The problem is that an array of different instances cannot be created when the constructor is parameterised. So the simple solution is to change your sketch so you have explicitly declared separate instances e.g.:
|
Beta Was this translation helpful? Give feedback.
-
I can't see a reason why it fails and I see in one of my examples I used and array of instances and it worked. I confirm the results, out of curiosity I created a simplified version and it works OK without the double buffering and dual processor: |
Beta Was this translation helpful? Give feedback.
-
It runs OK on my setup with PSRAM disabled. Maybe 4x faster as PSRAM to PSRAM copies are quite slow for large memory blocks. |
Beta Was this translation helpful? Give feedback.
-
Had another look at this and adapted to only update the screen in the needle zone. Needle angle increments must not be too big for this to work (i.e. not leave bits of needle image on screen) as it does not use the "old" angle zone. Performance then is much better, about 60fps with PSRAM and about 160fps when not using PSRAM for the sprites. This does not implement double buffering and one of the sprites created is not used, so that code can be deleted. A nice example for a dial. |
Beta Was this translation helpful? Give feedback.
-
Wow, that's fast! Even without using the second core.
Replacing the 30 with 45, the problem can be reproduced even with your example. (PSRAM disabled) If you want to add this code as an example, I am going to change the variable and function names so everything is in english. Also I would change the dial face a bit, because this might infringe some copyright laws^^' Out of curiosity, where did you buy your ESP32 with PSRAM? Thank you for your time investigating this. :-) EDIT: I attached an example omitting the unused stuff. |
Beta Was this translation helpful? Give feedback.
-
My board is a TTGO T8 with 4Mb PSRAM. Mine is v1.1, it is not the best board I have as the little on/off switch broke the first day of using and, with Windows 10, I usually need to press the BOOT button for it to program due to the boot timeout being too short. I updated the sketch to use a viewport in the destination sprite, this is set to the rotated needle bounding box and gives a performance boost to circa 100fps for PSRAM and 200fps for normal RAM. Due to PSRAM caching the speed varies significantly depending on the shape of the area to update, so a timed loop is required to keep the needle draw speed down. Here is my latest version. It has been an interesting distraction. Even with PSRAM the sprites were being incorrectly overwritten when the dual core is used, I think this may be down to limitations in the RTOS and the caching. As far as I can see there are no issues with the viewport feature or sprite handling in the library, so I assume that problem you had was related to the same memory over-write issue that has now been solved. |
Beta Was this translation helpful? Give feedback.
-
I expect you have realised that the needle rotated bounds should be calculated with the "old" angle, not the new one so the last needle image is over-written. Then the needle increment will not need to be small. The viewport bounds will then need to be updated for the new angle before drawing the new needle position. |
Beta Was this translation helpful? Give feedback.
-
If you have PSRAM this would be OK, but without it you can end up fragmenting the heap and then a sprite creation will fail at some point. One way is to create a square sprite with sides equal to the needle height plus margin. You must then move the pivot point for the needle rendering. |
Beta Was this translation helpful? Give feedback.
My board is a TTGO T8 with 4Mb PSRAM. Mine is v1.1, it is not the best board I have as the little on/off switch broke the first day of using and, with Windows 10, I usually need to press the BOOT button for it to program due to the boot timeout being too short.
I updated the sketch to use a viewport in the destination sprite, this is set to the rotated needle bounding box and gives a performance boost to circa 100fps for PSRAM and 200fps for normal RAM. Due to PSRAM caching the speed varies significantly depending on the shape of the area to update, so a timed loop is required to keep the needle draw speed down. Here is my latest version.
myDZM_array3.zip
It has been an interesting distra…