Browse Source

avoid crashes in attach_sky

cxgeorge 24 years ago
parent
commit
e888df5305
1 changed files with 6 additions and 3 deletions
  1. 6 3
      panda/src/testbed/demo.cxx

+ 6 - 3
panda/src/testbed/demo.cxx

@@ -460,7 +460,7 @@ event_h(CPT_Event) {
   }
   }
 }
 }
 
 
-static void attach_sky() {
+static bool attach_sky() {
   // Load the sun and sky
   // Load the sun and sky
   sky = DCAST(NamedNode, loader.load_sync("sky"));
   sky = DCAST(NamedNode, loader.load_sync("sky"));
   if (sky != (NamedNode *)NULL) {
   if (sky != (NamedNode *)NULL) {
@@ -468,6 +468,7 @@ static void attach_sky() {
       sky_arc = new RenderRelation(render, sky);
       sky_arc = new RenderRelation(render, sky);
     }
     }
   }
   }
+  return (sky!=NULL) && (sky_arc!=NULL);
 }
 }
 
 
 static void
 static void
@@ -507,7 +508,8 @@ static void
 event_v(CPT_Event) {
 event_v(CPT_Event) {
   static bool is_color_scale = false;
   static bool is_color_scale = false;
 
 
-  attach_sky();
+  if(!attach_sky())
+    return;
 
 
   NodePath search(sky);
   NodePath search(sky);
   NodePath sky_search = search.find("**/sun");
   NodePath sky_search = search.find("**/sun");
@@ -527,7 +529,8 @@ static void
 event_L(CPT_Event) {
 event_L(CPT_Event) {
   static bool is_flare = false;
   static bool is_flare = false;
 
 
-  attach_sky();
+  if(!attach_sky())
+    return;
 
 
   if (!is_flare) {
   if (!is_flare) {
     //Texture *shine = TexturePool::load_texture("MyShine.bw");
     //Texture *shine = TexturePool::load_texture("MyShine.bw");