General Issue with some wraps

Please post any questions about developing your plugin here. Please use the search function before posting!
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

General Issue with some wraps

Postby Omega_K2 » Mon Aug 05, 2013 11:26 am

Edit: Git -> https://github.com/Source-Python-Dev-Team/Source.Python/issues/3


Sometimes you can create objects of classes when you shouldn't be able to do because they are warpped, thus crashing the server when you call member functions.

Examples:
player_connect
-> IPlayerInfo does not work so early on (NULL afaik), but you can create an instance of CPlayerInfo, and once you call any member function the server crashes

CNetChannelInfo
-> INetChannelInfo returns NULL for bots, so if you use it on bots, server will crash


So in general this should be handled in the constructors properly, so we rather get a None value in python (like it was before the rewrite) instead of a server crash :P
Libraries: k2tools
Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)
Plugins (game-specific): None atm

If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Aug 06, 2013 2:26 am

Thanks for reporting. We will look into this.

Satoon
edcolmar
Junior Member
Posts: 21
Joined: Tue Oct 15, 2013 10:59 pm

Postby edcolmar » Sat Dec 14, 2013 11:15 pm

I seem to be hitting this issue also. I am trying to get a player's steam id on connect.

userid = game_event.get_int('userid')
print("userid: %s" % userid)
playerinfo = playerinfo_from_userid(userid)
print("playerinfo: %s" % playerinfo)
steamid = playerinfo.get_networkid_string()
print("player steamid: %s" % steamid)

Sometimes this causes a segmentation fault, sometimes it works.

Omega, would you be able to give an example of what you mean by: "this should be handled in the constructors properly". Is this something I am doing wrong on the plugin side?
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Sun Dec 15, 2013 12:58 am

edcolmar wrote:I seem to be hitting this issue also. I am trying to get a player's steam id on connect.

userid = game_event.get_int('userid')
print("userid: %s" % userid)
playerinfo = playerinfo_from_userid(userid)
print("playerinfo: %s" % playerinfo)
steamid = playerinfo.get_networkid_string()
print("player steamid: %s" % steamid)

Sometimes this causes a segmentation fault, sometimes it works.

Omega, would you be able to give an example of what you mean by: "this should be handled in the constructors properly". Is this something I am doing wrong on the plugin side?


I meant in c++/abstraction. I.e. they could be using a static factory function that simply returns null instead of the object with null points, that would resolve the problem (as null would be None)

I think checking for playerinfo with get_edict() and then is_valid() will work as a workaround.
Libraries: k2tools

Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)

Plugins (game-specific): None atm



If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython
edcolmar
Junior Member
Posts: 21
Joined: Tue Oct 15, 2013 10:59 pm

Postby edcolmar » Sun Dec 15, 2013 4:24 am

Thanks for the reply, but I don't quite follow. Could you paste an example?
edcolmar
Junior Member
Posts: 21
Joined: Tue Oct 15, 2013 10:59 pm

Postby edcolmar » Sun Dec 15, 2013 4:50 am

Is this close?

@Event
def player_connect(game_event):
print("Player Connect")
userid = game_event.get_int('userid')
print("userid: %s" % userid)
edict = edict_from_userid(userid)
playerinfo = edict.get_prop('playerinfo')



[SP] Caught an Exception:
Traceback (most recent call last):
File '../addons/source-python/packages/source-python/events/listener.py', line 82, in fire_game_event
callback(game_event)
File '../addons/source-python/plugins/leetcoin/leetcoin.py', line 464, in player_connect
playerinfo = edict.get_prop('playerinfo')

AttributeError: 'CEdict' object has no attribute 'get_prop'
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Dec 18, 2013 3:13 am

We changed the format to get SendProp values from:

Code: Select all

<CEdict>.get_prop('<prop name>').get_<type>()
to:

Code: Select all

<CEdict>.get_prop_<type>('<prop name>')
We just have not updated the Wiki to show those changes.

Also, playerinfo is not a SendProp name. You can get a player's CPlayerInfo instance by instantiating it using the player's userid or CEdict instance:

Code: Select all

playerinfo = CPlayerInfo(<userid>)

# or
playerinfo = CPlayerInfo(<CEdict>)


Satoon
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Thu Dec 19, 2013 9:32 am

edcolmar wrote:Thanks for the reply, but I don't quite follow. Could you paste an example?


Code: Select all

playerinfo = playerinfo_from_userid(userid)
# Avoid crash due to null pointer
if not playerinfo.get_edict().is_valid():
    return


Though as I said this is also an issue with SP, currently you can't check whether the playerinfo instance is valid, only the entity pointer. You'll have to avoid using it in cases where it is invalid.
Libraries: k2tools

Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)

Plugins (game-specific): None atm



If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 50 guests