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

Unified Diff: examples/ui/spinning_cube/spinning_cube_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/shapes/shapes_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/ui/spinning_cube/spinning_cube_view.cc
diff --git a/examples/ui/spinning_cube/spinning_cube_view.cc b/examples/ui/spinning_cube/spinning_cube_view.cc
index e478bde4a81a47193edaf2330253432bab3def8e..f4a806f75f942ec89da6a7a88999f46127479fa6 100644
--- a/examples/ui/spinning_cube/spinning_cube_view.cc
+++ b/examples/ui/spinning_cube/spinning_cube_view.cc
@@ -144,27 +144,34 @@ void SpinningCubeView::OnDraw(
cube_.UpdateForTimeDelta(time_delta.InSecondsF());
// Update the contents of the scene.
- 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();
- mojo::gfx::composition::ResourcePtr cube_resource = gl_renderer()->DrawGL(
- size, true, base::Bind(&SpinningCubeView::DrawCubeWithGL,
- base::Unretained(this), size));
- DCHECK(cube_resource);
- update->resources.insert(kCubeImageResourceId, cube_resource.Pass());
-
- auto root_node = mojo::gfx::composition::Node::New();
- root_node->content_transform = mojo::Transform::New();
- mojo::SetIdentityTransform(root_node->content_transform.get());
- root_node->hit_test_behavior = mojo::gfx::composition::HitTestBehavior::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 = kCubeImageResourceId;
- 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;
+
+ mojo::gfx::composition::ResourcePtr cube_resource = gl_renderer()->DrawGL(
+ size, true, base::Bind(&SpinningCubeView::DrawCubeWithGL,
+ base::Unretained(this), size));
+ DCHECK(cube_resource);
+ update->resources.insert(kCubeImageResourceId, cube_resource.Pass());
+
+ auto root_node = mojo::gfx::composition::Node::New();
+ root_node->content_transform = mojo::Transform::New();
+ mojo::SetIdentityTransform(root_node->content_transform.get());
+ root_node->hit_test_behavior =
+ mojo::gfx::composition::HitTestBehavior::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 = kCubeImageResourceId;
+ update->nodes.insert(kRootNodeId, root_node.Pass());
+ } else {
+ auto root_node = mojo::gfx::composition::Node::New();
+ update->nodes.insert(kRootNodeId, root_node.Pass());
+ }
scene()->Update(update.Pass());
« no previous file with comments | « examples/ui/shapes/shapes_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698