From 27842aa2f543c37a0d25ce246ff1b28faa186dc9 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Sun, 20 Feb 2022 01:04:04 +0100 Subject: [PATCH] Fix handheld maps not displaying in Minetest 5.5.0 The function dynamic_add_media() was changed in incompatible ways in several minor versions of Minetest, breaking the display of handheld maps in Minetest 5.5.0. This patch makes handheld maps display there. The function was blocking with one argument in Minetest 5.3. It was also blocking in Minetest 5.4, but took an additional argument for a function to execute once the media had been received. Calling dynamic_add_media() with a single argument had been deprecated; a function that did nothing was provided in mcl_maps to satisfy the changed argument requirements. In Minetest 5.5, dynamic_add_media() was changed to non-blocking. This introduced a race condition in mcl_maps, where a client often tried to display a map before it had received the map texture from the server. Opening an issue on the Minetest issue tracker led to it being closed in about 20 minutes: --- mods/ITEMS/mcl_maps/init.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index d2ff951ad..450d8fbad 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -147,11 +147,23 @@ function mcl_maps.load_map(id) local texture = "mcl_maps_map_texture_" .. id .. ".tga" if not loaded_maps[id] then - loaded_maps[id] = true - dynamic_add_media(map_textures_path .. texture, function() end) + if not minetest.features.dynamic_add_media_table then + -- minetest.dynamic_add_media() blocks in + -- Minetest 5.3 and 5.4 until media loads + loaded_maps[id] = true + dynamic_add_media(map_textures_path .. texture, function() end) + else + -- minetest.dynamic_add_media() never blocks + -- in Minetest 5.5, callback runs after load + dynamic_add_media(map_textures_path .. texture, function() + loaded_maps[id] = true + end) + end end - return texture + if loaded_maps[id] then + return texture + end end function mcl_maps.load_map_item(itemstack)