xml3d / xml3d.js

The WebGL/JS implementation of XML3D
Other
75 stars 25 forks source link

Assertion errror about aspect option set. #151

Closed Arsakes closed 8 years ago

Arsakes commented 8 years ago

Concerns latest commit: 1b2394bc106cb3c70ff82a6c5cc70e2aafe809c9. http://www.xml3d.org/xml3d/script/xml3d-5.0.0-min.js Following js code produces error: (XML3D is loaded using require.js)

requirejs(['jquery','xml3d'], function ($, XML3D) {
    $('body').append('<xml3d>');
} 

The error message:

AssertionError: aspect cannot both be non-zero.
at XML3D.extend.setFrustum (http://localhost:3000/scripts/libs/xml3d.js:19014:9)
at Object.XML3D.createClass._updateFrustum (http://localhost:3000/scripts/libs/xml3d.js:16417:22)
at Object.XML3D.createClass.getFrustum (http://localhost:3000/scripts/libs/xml3d.js:16426:14)
at XML3D.extend.getProjectionMatrix (http://localhost:3000/scripts/libs/xml3d.js:18646:40)
at EventEmitter.XML3D.extend.updateReadyObjectsFromActiveView          (http://localhost:3000/scripts/libs/xml3d.js:25350:24)
at XML3D.extend.render (http://localhost:3000/scripts/libs/xml3d.js:23785:19)
at XML3D.extend.renderTree (http://localhost:3000/scripts/libs/xml3d.js:23657:14)
at XML3D.extend.render (http://localhost:3000/scripts/libs/xml3d.js:24654:29)
at XML3D.extend.render (http://localhost:3000/scripts/libs/xml3d.js:24775:41)
at XML3D.extend.renderToCanvas (http://localhost:3000/scripts/libs/xml3d.js:25043:46)

The <xml3d></xml3d> html code works properly when used on static page.

csvurt commented 8 years ago

I'll take a look at this on Monday and add a few tests using require.js to our test suite, since it seems to cause problems more often than it should. Thanks for the report!

csvurt commented 8 years ago

I wasn't able to reproduce this on our side. I've attached a zip containing one of the test scenes I created, you should see an empty gray canvas followed by a canvas with a light purple background and a yellow square. Both XML3D and jquery are loaded through requirejs as you described above.

Could you check for any differences in the way this scene loads the scripts and your usage that leads to the error?

requirejs.zip | uploaded via ZenHub

Arsakes commented 8 years ago

There are few differences but the one I've found the be the reason is the dom element I append to, when i change it i either get the error or not. When the xml3d is loading the element I've append it to has set css styling display: none (It becomes visible only after every requirejs module has loaded fully). I've assumed it holds no relevance sorry for that.

Btw I'm (clearly) no expert on require.js but shouldn't you use it the usual way that is - reference some main script from

<script data-main="scripts/main.js" src="scripts/require.js"></script>
csvurt commented 8 years ago

Ahh, yeah that would cause problems. Elements with display: none have no width or height, and XML3D needs those to initialize (among other things) the canvas and the camera parameters.

If you want to hide the element while everything loads using visibility: hidden would be compatible with XML3D. The element will be invisible but will still be part of the page flow and have width and height properties. If you don't want it in the page flow either you could use position: absolute and keep it off screen until loading is finished, as long as it has valid dimensions it should work.

I'll add a note about this in our Wiki at least.

Arsakes commented 8 years ago

Thanks, I've just came to smiliar conclusions, I should have investigated it more closely before reporting sorry - you can close the issue.

csvurt commented 8 years ago

No problem, it was still useful to see that this is a potential problem that people might run into. In fact I think I'll add a check for null width and height so people will at least see a more helpful error message in the console in the future.