Merge pull request #5913 from djrm/fix_bake_segfault

Stop baking process if there is no geometry in the BakedLightInstance.
This commit is contained in:
Rémi Verschelde 2016-07-26 07:17:48 +02:00 committed by GitHub
commit bc6e750f95
4 changed files with 20 additions and 2 deletions

View file

@ -60,6 +60,8 @@ void BakedLightInstance::set_baked_light(const Ref<BakedLight>& p_baked_light) {
// VS::get_singleton()->instance_geometry_set_baked_light(E->get()->get_instance(),baked_light.is_valid()?get_instance():RID()); // VS::get_singleton()->instance_geometry_set_baked_light(E->get()->get_instance(),baked_light.is_valid()?get_instance():RID());
// } // }
} }
update_configuration_warning();
} }
Ref<BakedLight> BakedLightInstance::get_baked_light() const{ Ref<BakedLight> BakedLightInstance::get_baked_light() const{
@ -77,6 +79,14 @@ DVector<Face3> BakedLightInstance::get_faces(uint32_t p_usage_flags) const {
} }
String BakedLightInstance::get_configuration_warning() const {
if (get_baked_light().is_null()) {
return TTR("BakedLightInstance does not contain a BakedLight resource.");
}
return String();
}
void BakedLightInstance::_bind_methods() { void BakedLightInstance::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_baked_light","baked_light"),&BakedLightInstance::set_baked_light); ObjectTypeDB::bind_method(_MD("set_baked_light","baked_light"),&BakedLightInstance::set_baked_light);

View file

@ -55,6 +55,8 @@ public:
virtual AABB get_aabb() const; virtual AABB get_aabb() const;
virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const;
String get_configuration_warning() const;
BakedLightInstance(); BakedLightInstance();
}; };

View file

@ -1772,6 +1772,10 @@ void BakedLightBaker::bake(const Ref<BakedLight> &p_light, Node* p_node) {
mat_map.clear(); mat_map.clear();
tex_map.clear(); tex_map.clear();
print_line("\ttotal triangles: "+itos(triangles.size())); print_line("\ttotal triangles: "+itos(triangles.size()));
// no geometry
if (triangles.size() == 0) {
return;
}
ep.step(TTR("Fixing Lights"),1); ep.step(TTR("Fixing Lights"),1);
_fix_lights(); _fix_lights();
ep.step(TTR("Making BVH"),2); ep.step(TTR("Making BVH"),2);

View file

@ -206,8 +206,9 @@ void BakedLightEditor::_menu_option(int p_option) {
void BakedLightEditor::_bake_pressed() { void BakedLightEditor::_bake_pressed() {
ERR_FAIL_COND(!node); ERR_FAIL_COND(!node);
if (node->get_baked_light().is_null()) { const String conf_warning = node->get_configuration_warning();
err_dialog->set_text(TTR("BakedLightInstance does not contain a BakedLight resource.")); if (!conf_warning.empty()) {
err_dialog->set_text(conf_warning);
err_dialog->popup_centered_minsize(); err_dialog->popup_centered_minsize();
button_bake->set_pressed(false); button_bake->set_pressed(false);
return; return;
@ -236,6 +237,7 @@ void BakedLightEditor::_bake_pressed() {
update_timeout=0; update_timeout=0;
last_rays_time=0; last_rays_time=0;
button_bake->set_pressed(false);
set_process(true); set_process(true);
} }