Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Unified Diff: examples/ui/shapes/shapes_view.cc

Issue 1868093002: Mozart: Fix 0x0 crashes in example views. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/ui/png_viewer/png_viewer.cc ('k') | examples/ui/spinning_cube/spinning_cube_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/ui/shapes/shapes_view.cc
diff --git a/examples/ui/shapes/shapes_view.cc b/examples/ui/shapes/shapes_view.cc
index c4e2c9d298a704556963003e68500a8c1b008b03..ea18cb26c6db8ed5ba24486aa5ca22ce0f361d5b 100644
--- a/examples/ui/shapes/shapes_view.cc
+++ b/examples/ui/shapes/shapes_view.cc
@@ -34,30 +34,35 @@ void ShapesView::UpdateScene() {
if (!properties())
return;
- const mojo::Size& size = *properties()->view_layout->size;
- mojo::RectF bounds;
- bounds.width = size.width;
- bounds.height = size.height;
-
auto update = mojo::gfx::composition::SceneUpdate::New();
- // Draw the content of the view to a texture and include it as an
- // image resource in the scene.
- mojo::gfx::composition::ResourcePtr content_resource =
- ganesh_renderer()->DrawCanvas(
- size,
- base::Bind(&ShapesView::DrawContent, base::Unretained(this), size));
- DCHECK(content_resource);
- update->resources.insert(kContentImageResourceId, content_resource.Pass());
-
- // Add a root node to the scene graph to draw the image resource to
- // the screen such that it fills the entire view.
- auto root_node = mojo::gfx::composition::Node::New();
- root_node->op = mojo::gfx::composition::NodeOp::New();
- root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New());
- root_node->op->get_image()->content_rect = bounds.Clone();
- root_node->op->get_image()->image_resource_id = kContentImageResourceId;
- update->nodes.insert(kRootNodeId, root_node.Pass());
+ const mojo::Size& size = *properties()->view_layout->size;
+ if (size.width > 0 && size.height > 0) {
+ mojo::RectF bounds;
+ bounds.width = size.width;
+ bounds.height = size.height;
+
+ // Draw the content of the view to a texture and include it as an
+ // image resource in the scene.
+ mojo::gfx::composition::ResourcePtr content_resource =
+ ganesh_renderer()->DrawCanvas(
+ size,
+ base::Bind(&ShapesView::DrawContent, base::Unretained(this), size));
+ DCHECK(content_resource);
+ update->resources.insert(kContentImageResourceId, content_resource.Pass());
+
+ // Add a root node to the scene graph to draw the image resource to
+ // the screen such that it fills the entire view.
+ auto root_node = mojo::gfx::composition::Node::New();
+ root_node->op = mojo::gfx::composition::NodeOp::New();
+ root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New());
+ root_node->op->get_image()->content_rect = bounds.Clone();
+ root_node->op->get_image()->image_resource_id = kContentImageResourceId;
+ update->nodes.insert(kRootNodeId, root_node.Pass());
+ } else {
+ auto root_node = mojo::gfx::composition::Node::New();
+ update->nodes.insert(kRootNodeId, root_node.Pass());
+ }
// Submit the scene update.
scene()->Update(update.Pass());
« no previous file with comments | « examples/ui/png_viewer/png_viewer.cc ('k') | examples/ui/spinning_cube/spinning_cube_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698