resolutionScale for capturing a screenshot works in Sandcastle but not in tests
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
The unit tests for #5938 report double the expected value, however when running the code in Sandcastle the screen shot size matches the expected size.
This difference does not occur when resolutionScale is left at the default of 1.
**[Sandcastle example](https://sandcastle.cesium.com/#c=jVRNb9swDP0rQi6Wt0Hedm0aDO2KrUCADSnaXXxRZcYRJkuGJDvthv73UR9OnWYo6pNEvsf3SNMeuSWjhD1Yck407MklODl07C7GaCHi9dJoz6UGW5RntR6Rs5eN3yElcZkToIE1lu+lbi+G7Rbsr4DI6B3IdudfhX+PkIx3gitA+Gf2ESO1FkY7o4Ap09Li6qEH4ZFICvKe0OTkXeKUGCnIQ8jQLDplylgpVE89ob8WZp7m0WxDmK5X4IOTPJb9DjRrAP3SaRJSSy+5usmW52WYBbQ9eGl0TKdeXgEg32VgGgOO6WXNGMwAC50Z4aeFtXQewzYWCLPtLdz2DffAeNNcjaD9BKHbQYugSEvyt9YEn9grx4ruwE/Xs+d8ljLOn2phcAO6wSG+QWwqiOb4rVWhvajFvPkaQps1LWTHW6h63cZ9m1jT60hTG4HmEnPMqU06pZ+mw8nUIuSpzKuWRXprOumAeXzlz21Eyc310eii2/z5XIfzQTJmmNHK8AYB/x/G0XJ/Mz6udWKm3T6sdI6mxS5zV0dSzgrUySZjU7VefFgsnX9UsErIL7LrjfVksIoyVnnAhnFRXHU/iN+4YMK54H9ZTaRlI0cim/N68eJvUC+IUNw5zGwHpW7kH6gXq2WF+CNaaB+/1x8jWMUfA2T3abVOQcbYssLrKcsbo+65nVX8Bw)**
**Test Code**
```javascript
import createViewer from '../createViewer.js';
import when from '../../Source/ThirdParty/when.js';
describe('Scene/captureScreenshotBug', function() {
var container;
var viewer;
beforeAll(function() {
container = document.createElement('div');
container.id = 'container';
container.style.width = '20px';
container.style.height = '20px';
container.style.overflow = 'hidden';
container.style.position = 'relative';
document.body.appendChild(container);
});
afterAll(function() {
if (viewer && !viewer.isDestroyed()) {
viewer = viewer.destroy();
}
document.body.removeChild(container);
});
it('Fails in tests', function() {
viewer = createViewer(container);
var width = viewer.scene.drawingBufferWidth;
var height = viewer.scene.drawingBufferHeight;
var scale = 2.0;
console.log('Expecting ' + (width * scale) + ' x ' +(height * scale));
var cesiumWidget = viewer.cesiumWidget;
var complete = when.defer();
cesiumWidget.resolutionScale = scale;
var scene = cesiumWidget.scene;
var removePreListener = scene.preUpdate.addEventListener(function() {
var canvas = scene.canvas;
var removePostListener = scene.postRender.addEventListener(function() {
var dataUrl = canvas.toDataURL('image/png');
complete.resolve(dataUrl);
removePostListener();
});
removePreListener();
});
return complete.promise.then(function(dataURI) {
var loaded = when.defer();
var image = new Image();
image.onload = function() {
console.log('Got ' + image.width + ' x ' + image.height);
expect(image.width).toBe(width * scale);
expect(image.height).toBe(height * scale);
loaded.resolve();
};
image.src = dataURI;
return loaded.promise;
});
});
});
```
Browser: Chrome Version 78.0.3904.108 (Official Build) (64-bit)
Operating System: macOS Version 10.14.5
Contributor guide
Research direction
Start by running the supplied captureScreenshotBug test and trace createViewer through cesiumWidget.resolutionScale, scene preUpdate/postRender, and canvas.toDataURL. Compare the resulting image dimensions with the linked Sandcastle example; the work is done when resolutionScale produces consistent screenshot sizes in both environments while the default scale of 1 remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100