[niepce] Fix a crash when switching to the Darkroom without any image.



commit 3a9743a6de22eb8e1d1e249bfa18437d548a405b
Author: Hubert Figuiere <hub figuiere net>
Date:   Mon Jul 13 20:46:53 2009 -0400

    Fix a crash when switching to the Darkroom without any image.

 ChangeLog                                   |    2 ++
 src/ncr/image.cpp                           |   12 ++++++++++++
 src/niepce/modules/darkroom/imagecanvas.cpp |   12 +++++++++++-
 3 files changed, 25 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2e0c7bb..9463765 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2009-07-13  Hubert Figuiere  <hub figuiere net>
 
+	* Fix a crash when switching to the Darkroom without any image.
+
 	* Add UiController. Properly merge and unmerge UI and split
 	actions from NiepceWindow to the ModuleShell.
 
diff --git a/src/ncr/image.cpp b/src/ncr/image.cpp
index c8c9cf8..8bfdc47 100644
--- a/src/ncr/image.cpp
+++ b/src/ncr/image.cpp
@@ -215,6 +215,10 @@ void Image::reload(const std::string & p, bool is_raw,
 void Image::set_output_scale(double scale)
 {
     DBG_OUT("scale %f", scale);
+    if(!priv->m_scale) {
+        DBG_OUT("nothing loaded");
+        return;
+    }
     priv->m_scale->set("x", scale);
     priv->m_scale->set("y", scale);    
 
@@ -225,6 +229,10 @@ void Image::set_output_scale(double scale)
 
 void Image::set_tilt(double angle)
 {
+    if(!priv->m_rotate_n) {
+        DBG_OUT("nothing loaded");
+        return;
+    }
     priv->m_tilt = angle;
     priv->m_rotate_n->set("degrees", priv->m_orientation + priv->m_tilt);
 
@@ -267,6 +275,10 @@ void Image::rotate_by(int degree)
 
 Cairo::RefPtr<Cairo::Surface> Image::cairo_surface_for_display()
 {
+    if(!priv->m_output) {
+        DBG_OUT("nothing loaded");
+        return Cairo::RefPtr<Cairo::Surface>();
+    }
     priv->m_output->process();
     Gegl::Rectangle roi = priv->m_output->get_bounding_box();
     int w, h;
diff --git a/src/niepce/modules/darkroom/imagecanvas.cpp b/src/niepce/modules/darkroom/imagecanvas.cpp
index 024625a..b7bd21d 100644
--- a/src/niepce/modules/darkroom/imagecanvas.cpp
+++ b/src/niepce/modules/darkroom/imagecanvas.cpp
@@ -86,8 +86,14 @@ void ImageCanvas::_calc_image_frame(int img_w, int img_h,
 
 bool ImageCanvas::on_expose_event(GdkEventExpose *ev)
 {
-    Cairo::RefPtr<Cairo::Context> context = get_window()->create_cairo_context();
+    // no image, just pass.
+    if(!m_image) {
+        DBG_OUT("no image");
+        return false;
+    }
 
+
+    Cairo::RefPtr<Cairo::Context> context = get_window()->create_cairo_context();
     context->rectangle(ev->area.x, ev->area.y, ev->area.width, ev->area.height);
     context->clip();
 
@@ -107,6 +113,10 @@ bool ImageCanvas::on_expose_event(GdkEventExpose *ev)
         // query the image.
         Cairo::RefPtr<Cairo::Surface> img_s 
             = m_image->cairo_surface_for_display();
+        if(!img_s) {
+            DBG_OUT("no image loaded");
+            return false;
+        }
 
         int canvas_h, canvas_w;
         canvas_h = get_height();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]