Fixed an issue where Non-networked entities could not be created.#342
Conversation
|
What's your from entities.entity import BaseEntity
print(BaseEntity.create('info_player_terrorist')) |
|
I can reproduce it on both Linux and Windows. Linux Windows Others have also reproduced this problem. |
|
I tested on CS:S, turns out that entity is networked on that game. I was able to reproduce using an This brought another point we should probably change as well, where while it is correct to silence all exceptions into the class Ent(BaseEntity):
def __init__(self, index):
1 / 0
@classmethod
def _obj(cls, ptr):
1 / 0
Ent.create('info_player_terrorist')Would currently raises the following: ValueError: Unable to make a 'Ent' instance out of this 'info_player_terrorist' entity.While it should really raises: ZeroDivisionError: division by zeroThe following should have the correct behaviour without silencing any and all exceptions that weren't expected: object CBaseEntityWrapper::create(object cls, const char *name)
{
object entity = object();
CBaseEntityWrapper *pEntity = (CBaseEntityWrapper *)create(name);
try
{
entity = cls(pEntity->GetIndex());
}
catch (...)
{
if (!PyErr_ExceptionMatches(PyExc_ValueError))
throw_error_already_set();
PyErr_Clear();
try
{
CPointer tmp = pEntity->GetPointer();
entity = MakeObject(cls, &tmp);
}
catch (...)
{
pEntity->remove();
if (!PyErr_ExceptionMatches(PyExc_ValueError))
throw_error_already_set();
else
{
const char *classname = extract<const char *>(cls.attr("__qualname__"));
BOOST_RAISE_EXCEPTION(
PyExc_ValueError,
"Unable to make a '%s' instance out of this '%s' entity.",
classname, name
)
}
}
}
return entity;
}If it works as expected for you, please update your PR and I will merge it. Thanks for the report, and the fix! 👍 |
|
That works as expected if you load the plugin by server.cfg, but if you load the plugin afterwards, it will have a different result. Loaded via server.cfg: Loaded from the terminal: |
|
Hmm. That's actually interesting. The logic appears correct, but I suspect the fact of re-throwing the |
This solves the problem of creating Non-networked entities.
This issue was discovered by @progre.
Code:
Output:
or
Output:
When getting the Index of a Non-networked entity, an exception will be raised, so we need to clear the error indicator.
Source.Python/src/core/utilities/conversions.h
Lines 81 to 93 in d65dc58