Closed tobozo closed 3 years ago
@tobozo Thanks for the report.
I was not able to reproduce the problem, but I updated the develop branch with a change to discard the sprites once when setPsram is changed.
Are there any other prerequisites to reproduce the problem? If you change the board type, will the problem go away?
[edit] simplified POC code [edit2] : pinpointed the issue
static LGFX_Sprite *sprite = new LGFX_Sprite( &tft ); // no crash when using this
static TFT_eSprite *sprite = new TFT_eSprite( &tft ); // will crash on createSprite()
The problem seems to be isolated to LoLin D32 Pro + TFT-2.4. No other component is connected.
I can't reproduce this issue on M5Stack or Odroid-Go.
Updating the develop branch did not solve it,
Are there any other prerequisites to reproduce the problem?
I have reduced the crash code to this:
#include <ESP32-Chimera-Core.h>
#define tft M5.Lcd
class BLAH {
public:
BLAH(){
if( !psramInit() ) {
log_e("Failed to init psram, crash will probably occur");
} else {
log_d("Psram successfully detected");
}
};
~BLAH() { };
};
static BLAH bleb;
// static LGFX_Sprite *keyNoteSprite = new LGFX_Sprite( &tft ); // no crash when using this
static TFT_eSprite *keyNoteSprite = new TFT_eSprite( &tft );
void setup()
{
M5.begin();
void* sptr = keyNoteSprite->createSprite( tft.width(), tft.height() );
if( !sptr ) {
log_e("Can't create sprite, aborting");
while(1) vTaskDelay(1);
}
}
void loop()
{
}
... is premature psramInit()
causing this ?
The psramInit function seems to be called at startup in the initArduino function. I don't see any need to call it explicitly from user code. If you call it in the constructor of a static object, I think it is called before initArduino.
Therefore, this is sufficient to reproduce the problem.
#include <Arduino.h>
#include <esp_log.h>
class BLAH {
public:
BLAH(){
if( !psramInit() ) {
log_e("Failed to init psram, crash will probably occur");
} else {
log_d("Psram successfully detected");
}
};
~BLAH() { };
};
static BLAH bleb;
void setup()
{
void* sptr = heap_caps_malloc(320*240*2, MALLOC_CAP_SPIRAM);
if( !sptr ) {
log_e("Can't heap_caps_malloc, aborting");
}
else
{
log_e("success !");
}
}
void loop()
{
vTaskDelay(1);
}
ok I understand this is a bad practice causing that, I'm not sure why it only crashes with LoLin D32 Pro + TFT-2.4 though.
closing this issue as not a LGFX problem
Hardware: LoLin D32Pro (with psram) + TFT-2.4 @320x240
Problem description:
sprite::createSprite()
crashes when used in combination with psram.Expected behaviour:
createSprite should return NULL when allocation failed
How to reproduce:
Error message in the console:
Decoded backtrace: