Error while creating offscreen canvas element

Asked by Johan Axelsson

Hi,
the program below crasches when I create the HTMLCanvasElement, only the first console log message shows up on the console.

Regards Johan

void webMain() [[cheerp::client]]
{
  // OnDomLoaded
  auto OnDomLoaded = [=](){
    console.log("Before creating client::HTMLCanvasElement()");
    auto canvas = new client::HTMLCanvasElement();
    console.log("After creating client::HTMLCanvasElement()");
  };
  document.addEventListener("DOMContentLoaded",cheerp::Callback(OnDomLoaded));
}

Question information

Language:
English Edit question
Status:
Solved
For:
Cheerp Edit question
Assignee:
No assignee Edit question
Solved by:
Alessandro Pignotti
Solved:
Last query:
Last reply:
Revision history for this message
Best Alessandro Pignotti (a-pignotti) said :
#1

HTML elements needs to be created from the document object. The following syntax should work.

auto canvas = (client::HTMLCanvasElement*)document.createElement("canvas");

Revision history for this message
Johan Axelsson (johan-axelsson) said :
#2

Thanks Alessandro Pignotti, that solved my question.