Skip to content

Commit

Permalink
Fix potencial get_stackdata call before on_activate call. Update doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfence committed Jan 28, 2024
1 parent 81b9206 commit ca0a57d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5948,8 +5948,11 @@ Environment access
* `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at
position.
* Returns `ObjectRef`, or `nil` if failed
* Entities with `static_save = true` can be added also
to unloaded/nongenerated blocks.
* `minetest.add_item(pos, item)`: Spawn item
* Returns `ObjectRef`, or `nil` if failed
* Items can be added also to unloaded/nongenerated blocks.
* `minetest.get_player_by_name(name)`: Get an `ObjectRef` to a player
* `minetest.get_objects_inside_radius(pos, radius)`: returns a list of
ObjectRefs.
Expand Down
13 changes: 8 additions & 5 deletions src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,11 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
return 0;
}

// Register reference in scripting api (must be done before post-init)
m_script->addObjectReference(object);
// Post-initialize object
object->addedToEnvironment(dtime_s);

// Add static data to block
if (object->isStaticAllowed()) {
// Add static object to active static list of the block
Expand All @@ -1922,16 +1927,14 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
errorstream << "ServerEnvironment::addActiveObjectRaw(): "
<< "could not emerge block " << p << " for storing id="
<< object->getId() << " statically" << std::endl;
// clean in case of error
object->removingFromEnvironment();
m_script->removeObjectReference(object);
m_ao_manager.removeObject(object->getId());
return 0;
}
}

// Register reference in scripting api (must be done before post-init)
m_script->addObjectReference(object);
// Post-initialize object
object->addedToEnvironment(dtime_s);

return object->getId();
}

Expand Down

0 comments on commit ca0a57d

Please sign in to comment.