Issue while displaying an image

35 views
Skip to first unread message

25. Sai Surya

unread,
May 29, 2022, 11:45:20 PM5/29/22
to Developing Interactive Simulations in HTML5
Hi All,

I am trying to add an image to simulation which is pretty basic use case. But, I'm getting below error. From the error it is obvious that, TableNode is not initialized properly, causing failure to read property 'size' when trying to scale node.

TableNode.js? [sm]:42 Uncaught TypeError: Cannot read properties of undefined (reading 'size')
    at new TableNode (TableNode.js? [sm]:42:64)

Line 42 where error is showing here:

const scaleX = modelViewTransform.modelToViewDeltaX( table.size.width ) / this.width;

In fact, I am able to display some other image with similar approach, but when I try to add another image giving above error.

Any clues?

Thanks in advance
Sai Surya

25. Sai Surya

unread,
May 30, 2022, 8:18:51 AM5/30/22
to Developing Interactive Simulations in HTML5
I further debuged, it seems addChild in the screen view not initializing model correctly. Below is code ...

// In screen view ...
// Add a football. The model determines its position.
    this.addChild( new FootBallNode( model.footBall, modelViewTransform ) );   //This is fine.
 
    // Add a table. The model determines its position.
    this.addChild( new TableNode( model.table, modelViewTransform ) ); // This is not adding model correctly, hence above error that model is 'undefined'

How can I add multiple children to a single screen view? Or am I missing something?

Thanks in advance
Sai Surya

samrreid

unread,
May 31, 2022, 11:18:43 AM5/31/22
to Developing Interactive Simulations in HTML5
Greetings!

From the messages above, it seems like model.table is not defined at that time.  Can you please share the code where model.table is instantiated?

Best Regards,
Sam

Reply all
Reply to author
Forward
0 new messages