Skip to content

Commit

Permalink
Register.lua: Throw error if node 'light_source' > core.LIGHT_MAX
Browse files Browse the repository at this point in the history
Add 'core.LIGHT_MAX = 14' to builtin/game/constants.lua with the intention
to replace misplaced 'default.LIGHT_MAX = 14' in Minetest Game.
Add comment in light.h requiring the constant be changed in both places.
Add lighting bug warning to note in lua_api.txt.
There are hundreds of mod uses of 15 which causes a lighting bug.
  • Loading branch information
paramat committed Sep 17, 2016
1 parent 297546a commit 3aefa5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions builtin/game/constants.lua
Expand Up @@ -19,4 +19,9 @@ core.EMERGE_FROM_DISK = 3
core.EMERGE_GENERATED = 4

-- constants.h
-- Size of mapblocks in nodes
core.MAP_BLOCKSIZE = 16

-- light.h
-- Maximum value for node 'light_source' parameter
core.LIGHT_MAX = 14
3 changes: 3 additions & 0 deletions builtin/game/register.lua
Expand Up @@ -127,6 +127,9 @@ function core.register_item(name, itemdef)
fixed = {-1/8, -1/2, -1/8, 1/8, 1/2, 1/8},
}
end
if itemdef.light_source and itemdef.light_source > core.LIGHT_MAX then
error("Unable to register node: 'light_source' exceeds maximum: " .. name)
end
setmetatable(itemdef, {__index = core.nodedef_default})
core.registered_nodes[itemdef.name] = itemdef
elseif itemdef.type == "craft" then
Expand Down
5 changes: 4 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -3664,7 +3664,10 @@ Definition tables
^ Don't forget to use "leveled" type nodebox. ]]
liquid_range = 8, -- number of flowing nodes around source (max. 8)
drowning = 0, -- Player will take this amount of damage if no bubbles are left
light_source = 0, -- Amount of light emitted by node (max. 14)
light_source = 0, --[[
^ Amount of light emitted by node.
^ To set the maximum (currently 14), use the value 'minetest.LIGHT_MAX'.
^ A value outside the range 0 to minetest.LIGHT_MAX causes undefined behavior.]]
damage_per_second = 0, -- If player is inside node, this damage is caused
node_box = {type="regular"}, -- See "Node boxes"
connects_to = nodenames, --[[
Expand Down
6 changes: 4 additions & 2 deletions src/light.h
Expand Up @@ -27,8 +27,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/

// This directly sets the range of light.
// Actually this is not the real maximum, and this is not the
// brightest. The brightest is LIGHT_SUN.
// Actually this is not the real maximum, and this is not the brightest, the
// brightest is LIGHT_SUN.
// If changed, this constant as defined in builtin/game/constants.lua must
// also be changed.
#define LIGHT_MAX 14
// Light is stored as 4 bits, thus 15 is the maximum.
// This brightness is reserved for sunlight
Expand Down

11 comments on commit 3aefa5d

@Fixer-007
Copy link
Contributor

@Fixer-007 Fixer-007 commented on 3aefa5d Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paramat but why preventing server start if you can output simple warning to console/debug.txt and leave server admin headache-free?

Quoting cheapie:

OK, so I see that quite a few mods are using invalid light_source settings... wouldn't it have been better to give a warning than to crash the server when that happens?
I had to fix 6 mods just to get one world to load.

@cheapie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to modify six mods to make one world load after this.

@paramat
Copy link
Contributor Author

@paramat paramat commented on 3aefa5d Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warnings are not always seen and 15 causes a serious and difficult-to-fix lighting bug. So we thought the strictness justified.
It's no extra work to fix things now instead of later.
However we could make it a warning and auto-limit to 14 @sofar ?
Easy to code so someone else could do that, we're busy.

@cheapie
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen any lighting issues before from mods using a light_source of 15 (or the completely-invalid 30, like blox did for some reason). Is there an issue report here somewhere for it?

@VanessaE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"we're busy", says the guy whose committed code broke a bunch of mods. Seriously?

@paramat
Copy link
Contributor Author

@paramat paramat commented on 3aefa5d Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #3964 (comment)
When adding and removing the node infinitely propagating light is created, i don't yet know of a way to fix it, maybe a mod using a voxelmanip to reset lighting.

whose committed code broke a bunch of mods

What code broke what mods? We solved a widespread and serious bug and added notification to avoid it, there are many other situations where node definition errors will halt the game, it's not unusual.
We are indeed busy and a simple PR could be done by a contributor. Not saying we'll agree to a less strict notification though, i'm undecided.

@VanessaE
Copy link
Contributor

@VanessaE VanessaE commented on 3aefa5d Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a mod works before the commit, and fails after, and nothing functional about the mod has actually changed, then by definition the engine broke the mod. If there are "hundreds" of bad uses of lighting values around, then that alone was sufficient reason not to throw an error.

@paramat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree it's breakiing, if anything it's fixing. Ok i'll change it now to a warning plus auto-limit,
15 is so widespread and likely to persist for months and not everyone knows how to edit mods,

@paramat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paramat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found how to fix the lighting bug, it's easy when you know how.

@paramat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4538 merged.

Please sign in to comment.