← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/editor-remove-invalid-resources_fix into lp:~janosch-peters/widelands/editor-remove-invalid-resources

 

Tino has proposed merging lp:~widelands-dev/widelands/editor-remove-invalid-resources_fix into lp:~janosch-peters/widelands/editor-remove-invalid-resources.

Requested reviews:
  Janosch Peters (janosch-peters)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/editor-remove-invalid-resources_fix/+merge/281467

avoid crash when setting resource amount to 0 on empty field
-- 
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/editor-remove-invalid-resources_fix.
=== modified file 'src/editor/tools/editor_set_resources_tool.cc'
--- src/editor/tools/editor_set_resources_tool.cc	2016-01-01 17:35:01 +0000
+++ src/editor/tools/editor_set_resources_tool.cc	2016-01-02 14:34:02 +0000
@@ -57,10 +57,11 @@
 
 		if (editor_change_resource_tool_callback(mr.location(), map, world, args.cur_res)) {
 			//  Ok, we're doing something. First remove the current overlays.
-			const Image* pic = g_gr->images().get
-				(world.get_resource(res)->get_editor_pic (mr.location().field->get_resources_amount()));
-			overlay_manager.remove_overlay(mr.location(), pic);
-
+			if (res != Widelands::kNoResource) {
+				const Image* pic = g_gr->images().get
+					(world.get_resource(res)->get_editor_pic (mr.location().field->get_resources_amount()));
+				overlay_manager.remove_overlay(mr.location(), pic);
+			}
 			if (!amount) {
 				mr.location().field->set_resources(Widelands::kNoResource, 0);
 				mr.location().field->set_initial_res_amount(0);
@@ -68,7 +69,7 @@
 				mr.location().field->set_resources(args.cur_res, amount);
 				mr.location().field->set_initial_res_amount(amount);
 				//  set new overlay
-				pic =
+				const Image* pic =
 				    g_gr->images().get(world.get_resource(args.cur_res)->get_editor_pic(amount));
 				overlay_manager.register_overlay(mr.location(), pic, 4);
 				map.recalc_for_field_area(world, Widelands::Area<Widelands::FCoords>(mr.location(), 0));


Follow ups