Page 1 of 1

RuntimeError: access violation - no RTTI data

Posted: Sun Sep 29, 2013 9:47 pm
by Omega_K2
Also posted on GitHub: https://github.com/Source-Python-Dev-Team/Source.Python/issues/2

It was though to find code that actually replicates this issue, because at first it seemed to happen quite randomly. There might be more cases then this one.

It seems to happen when passing/storing playerinfo objects to multiple functions; I'm guessing they go out of scope when the first function finishes execution:

To reproduce

Code: Select all

import command_c

def h(playerinfo, command):
    test(playerinfo)
    test(playerinfo)
   
def test(playerinfo):
    e = playerinfo.get_edict()
    e.get_index()
    print(e)

def load():
    command_c.register_client_command_filter(h)
   
def unload():
    command_c.unregister_client_command_filter(h)


Which will result in:

Code: Select all

<entity_c.CEdict object at 0x12345678>
(Traceback here)
RuntimeError: access violation - no RTTI data

Posted: Mon Sep 30, 2013 4:12 am
by Omega_K2
Okay, it seems Python will garbage collect the edict instance because it thinks there are no more references to it, so solution is to either create a new object and return it OR make sure it doesn't get collected (adding __del__ should do that job, but it cause other problems):

So in fix players_wrap.cpp:

Code: Select all

CEdict* CPlayerInfo::get_edict() const
{
   return new CEdict(m_edict_ptr->get_edict());
}


See also: https://github.com/OmegaK2/Source.Python/tree/fixes