Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix segfaults caused by the Environment not being initialized yet
  • Loading branch information
rubenwardy authored and est31 committed Aug 9, 2015
1 parent 6b39bc6 commit a953ff4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/lua_api.txt
Expand Up @@ -2192,7 +2192,7 @@ These functions return the leftover itemstack.

* `minetest.add_particlespawner(particlespawner definition)`
* Add a `ParticleSpawner`, an object that spawns an amount of particles over `time` seconds
* Returns an `id`
* Returns an `id`, and -1 if adding didn't succeed

This comment has been minimized.

Copy link
@ShadowNinja

ShadowNinja Sep 19, 2015

Member

nil would be more consistent with the rest of the API.

This comment has been minimized.

Copy link
@rubenwardy

rubenwardy Sep 19, 2015

Author Member

the function below returns an integer, which is why it was done as -1 : the Lua wrapper should translate this to nil, however.

* `Deprecated: minetest.add_particlespawner(amount, time,
minpos, maxpos,
minvel, maxvel,
Expand Down
20 changes: 20 additions & 0 deletions src/server.cpp
Expand Up @@ -2857,6 +2857,10 @@ std::string Server::getBanDescription(const std::string &ip_or_name)

void Server::notifyPlayer(const char *name, const std::wstring &msg)
{
// m_env will be NULL if the server is initializing
if (!m_env)
return;

Player *player = m_env->getPlayer(name);
if (!player)
return;
Expand All @@ -2870,6 +2874,10 @@ void Server::notifyPlayer(const char *name, const std::wstring &msg)
bool Server::showFormspec(const char *playername, const std::string &formspec,
const std::string &formname)
{
// m_env will be NULL if the server is initializing
if (!m_env)
return false;

Player *player = m_env->getPlayer(playername);
if (!player)
return false;
Expand Down Expand Up @@ -3039,6 +3047,10 @@ void Server::spawnParticle(const std::string &playername, v3f pos,
float expirationtime, float size, bool
collisiondetection, bool vertical, const std::string &texture)
{
// m_env will be NULL if the server is initializing
if (!m_env)
return;

u16 peer_id = PEER_ID_INEXISTENT;
if (playername != "") {
Player* player = m_env->getPlayer(playername.c_str());
Expand All @@ -3057,6 +3069,10 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime,
bool collisiondetection, bool vertical, const std::string &texture,
const std::string &playername)
{
// m_env will be NULL if the server is initializing
if (!m_env)
return -1;

u16 peer_id = PEER_ID_INEXISTENT;
if (playername != "") {
Player* player = m_env->getPlayer(playername.c_str());
Expand Down Expand Up @@ -3088,6 +3104,10 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime,

void Server::deleteParticleSpawner(const std::string &playername, u32 id)
{
// m_env will be NULL if the server is initializing
if (!m_env)
throw ServerError("Can't delete particle spawners during initialisation!");

u16 peer_id = PEER_ID_INEXISTENT;
if (playername != "") {
Player* player = m_env->getPlayer(playername.c_str());
Expand Down

0 comments on commit a953ff4

Please sign in to comment.