Server stops after OnPlayerSpawn
#1

Hello there people! I have a really serious problem which I can't deal with. When I spawn, my server crashes.

OnPlayerSpawn:
PHP код:
public OnPlayerSpawn(playerid)
{
    new
        
Query[250],
        
DBResultResult,
        
pName[250],
         
Field[20],
        
Field2[20],
         
Field3[20],
        
Field4[20]
    ;
    
GetPlayerName(playeridpNamesizeof(pName));
    
    
format(Querysizeof(Query), "SELECT * FROM `Accounts` WHERE Name = '%s'"DB_Escape(pName));
    
Result db_query(DatabaseQuery);
    
db_get_field_assoc(Result"Skin"Field30);
    
SetPlayerSkin(playeridstrval(Field));
    
    
db_get_field_assoc(Result"Interior"Field30);
    
SetPlayerInterior(playeridstrval(Field));
    
    
db_get_field_assoc(Result"Angle"Field30);
    
SetPlayerFacingAngle(playeridstrval(Field));
    
    
db_get_field_assoc(Result"Skin"Field30);
    
SetPlayerSkin(playeridstrval(Field));
    
    
db_get_field_assoc(Result"X"Field230);
    
format(Fieldsizeof(Field2), "%f"Field2);
    
    
db_get_field_assoc(Result"Y"Field330);
    
format(Fieldsizeof(Field3), "%f"Field3);
    
    
db_get_field_assoc(Result"Z"Field430);
    
format(Fieldsizeof(Field4), "%f"Field4);
    
    
SetPlayerPos(playeridstrval(Field2), strval(Field3), strval(Field4));
    
SetCameraBehindPlayer(playerid);
    
db_free_result(Result);
     return 
1;

If I solve my problem, the helper gets a rep from me.
Reply
#2

Quote:
Originally Posted by Wiki
Using an invalid handle will crash your server! Get a valid handle by using db_query. But it's protected against NULL references.
Other:
- Use the new functions such as getting a value from the database as an integer/float.
- Fix the cells you specified, player names are up to 24 chars, those field variables you created are set to 20 but you put 30 in the function.
- Learn to debug your code, you can find the exact issue (to debug add prints after calling each function, see where it stops at).
- Load crashdetect plugin. Read and find the issue based on what it prints.
Reply
#3

You don't check if there are rows before retrieving the data.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You don't check if there are rows before retrieving the data.
Didn't work.
PHP код:
public OnPlayerSpawn(playerid)
{
    new
        
Query[250],
        
DBResultResult,
        
pName[250],
         
Field[20],
        
Field2[20],
         
Field3[20],
        
Field4[20]
    ;
    
GetPlayerName(playeridpNamesizeof(pName));
    
    
format(Querysizeof(Query), "SELECT * FROM `Accounts` WHERE Name = '%s'"DB_Escape(pName));
    
Result db_query(DatabaseQuery);
    if(
db_num_rows(Result))
    {
        
db_get_field_assoc(Result"Skin"Field30);
        
SetPlayerSkin(playeridstrval(Field));
        
db_get_field_assoc(Result"Interior"Field30);
        
SetPlayerInterior(playeridstrval(Field));
        
db_get_field_assoc(Result"Angle"Field30);
        
SetPlayerFacingAngle(playeridstrval(Field));
        
db_get_field_assoc(Result"Skin"Field30);
        
SetPlayerSkin(playeridstrval(Field));
        
db_get_field_assoc(Result"X"Field230);
        
format(Fieldsizeof(Field2), "%f"Field2);
        
db_get_field_assoc(Result"Y"Field330);
        
format(Fieldsizeof(Field3), "%f"Field3);
        
db_get_field_assoc(Result"Z"Field430);
        
format(Fieldsizeof(Field4), "%f"Field4);
        
SetPlayerPos(playeridstrval(Field2), strval(Field3), strval(Field4));
        
SetCameraBehindPlayer(playerid);
    }
    
db_free_result(Result);
     return 
1;

Reply
#5

Like SickAttack said, load crashdetect plugin to see what is causing the crash. If the data in a column retrieved was null, it used to crash but that is supposed fixed in 0.3.7 R* version.

The thing I'm unsure is if you try to retrieve a field that does not exist, you better enable db_logging (in server.cfg, set that setting to 1).
Reply
#6

I loaded crashdetect.dll and no errors detected. I also set db_logging to 1. Didn't work though.

server_log:

Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7, ©2005-2015 SA-MP Team

[12:24:25] 
[12:24:25] Server Plugins
[12:24:25] --------------
[12:24:25]  Loading plugin: sscanf.dll
[12:24:25] 

[12:24:25]  ===============================

[12:24:25]       sscanf plugin loaded.     

[12:24:25]          Version:  2.8.1        

[12:24:25]    © 2012 Alex "******" Cole  

[12:24:25]  ===============================

[12:24:25]   Loaded.
[12:24:25]  Loading plugin: Whirlpool.dll
[12:24:25]  
[12:24:25]  ==================
[12:24:25]  
[12:24:25]   Whirlpool loaded
[12:24:25]  
[12:24:25]  ==================
[12:24:25]  
[12:24:25]   Loaded.
[12:24:25]  Loading plugin: audio.dll
[12:24:25] 

*** Audio Plugin v0.5 R2 by Incognito loaded ***

[12:24:25]   Loaded.
[12:24:25]  Loading plugin: crashdetect.dll
[12:24:25]   CrashDetect v4.16 is OK.
[12:24:25]   Loaded.
[12:24:25]  Loading plugin: streamer.dll
[12:24:25] 

*** Streamer Plugin v2.5.2 by Incognito loaded ***

[12:24:25]   Loaded.
[12:24:25]  Loading plugin: FCNPC.dll
[12:24:25] 
[12:24:25] -------------------------------------------------
[12:24:25]      FCNPC - Fully Controllable NPC v1.0.5
[12:24:25] 
[12:24:25] - Author: OrMisicL
[12:24:25] - Contributors: ziggi, Neutralneu
[12:24:25] - Server version: 0.3.7
[12:24:25] - Build: Apr 17 2016 at 01:34:41
[12:24:25] -------------------------------------------------
[12:24:25] 
[12:24:25] Loading...
[12:24:25]   Loaded.
[12:24:25]  Loaded 6 plugins.

[12:24:25] 
[12:24:25] Filterscripts
[12:24:25] ---------------
[12:24:25]   Loading filterscript 'GarHouse.amx'...
[12:24:25] Warning: the maxplayers limit is less than maxnpc (possible crash)
[12:24:25]  
[12:24:25]  ======================================= 
[12:24:25]  |                                     | 
[12:24:25]  |        YSI version 1.03.0011        | 
[12:24:25]  |        By Alex "******" Cole        | 
[12:24:25]  |                                     | 
[12:24:25]  |  Checking the latest YSI version..  | 
[12:24:25]  |                                     | 
[12:24:25]  ======================================= 
[12:24:25]  
[12:24:25] 
>> Attempting to load GarHouse v2.0... <<

[12:24:25] *** Audio Plugin: Started TCP server on port 7777
[12:24:25] 
Total House Interiors Loaded: 11. Duration: 4 ms

[12:24:25] 
Total Houses Loaded: 7. Duration: 20 ms

[12:24:25] 
>> GarHouse v2.0 By [03]Garsino Loaded <<

[12:24:25]   Loading filterscript 'key2.amx'...
[12:24:25] 
--------------------------------------
[12:24:25]  >> Filterscript "Key 2" Loaded! <<
[12:24:25] --------------------------------------

[12:24:25]   Loading filterscript 'TimeSP.amx'...
[12:24:25] TLN's Time, Week & Day System Loaded!
[12:24:25]   Loading filterscript 'Sleep_System.amx'...
[12:24:25]  
[12:24:25]  
[12:24:25]  
[12:24:25]  ======================================= 
[12:24:25]  |                                     | 
[12:24:25]  |        YSI version 4.00.0001        | 
[12:24:25]  |        By Alex "******" Cole        | 
[12:24:25]  |                                     | 
[12:24:25]  ======================================= 
[12:24:25]  
[12:24:25] 
--------------------------------------------
[12:24:25] ! Using Sleep System by GoKkuU aka Frederico !
[12:24:25] --------------------------------------------

[12:24:25]   Loading filterscript 'CAccounts.amx'...
[12:24:25] 
--------------------------------------
[12:24:25]  Accounts system by Christolis. (LOADED)
[12:24:25] --------------------------------------

[12:24:25]   Loading filterscript 'zones.amx'...
[12:24:25] 
--------------------------------------
[12:24:25]  Zone System 0.1 by RoamPT 
[12:24:25] --------------------------------------

[12:24:25]   Loaded 6 filterscripts.

[12:24:25] *** Audio_SetPack: Audio pack set to "HotDog" (transferable and automated)
[12:24:25] ------------------------------------
[12:24:25]  Roreplay Gamemode by Christolis
[12:24:25] ------------------------------------
[12:24:25] Number of vehicle models: 36
[12:24:25]  
[12:24:25]  ========================================== 
[12:24:25]  |                                        | 
[12:24:25]  |  A new version (v3.09.0684) of YSI is  | 
[12:24:25]  |            available from:             | 
[12:24:25]  |                                        | 
[12:24:25]  |     www.y-less.com/YSI/YSI_1.0.zip     | 
[12:24:25]  |                                        | 
[12:24:25]  | Changelog:                             | 
[12:24:25]  |                                        | 
[12:24:25]  |   1.04.0000:                           | 
[12:24:25]  |                                        | 
[12:24:25]  |   RC 1 for YSI 3.0.  Available from:   | 
[12:24:25]  | http://www.y-less.com/YSI/YSI_3.0.rar  | 
[12:24:25]  | - includes MANY new libraries and      | 
[12:24:25]  | fixes, see                             | 
[12:24:25]  | http://forum.sa-mp.com/showthread.php? | 
[12:24:25]  | p=1425938 for more information, with   | 
[12:24:25]  | more topics and updates due over the   | 
[12:24:25]  | next few weeks.  In brief: Added       | 
[12:24:25]  | "y_inline", "y_text", "y_users",       | 
[12:24:25]  | "y_uvar", "y_svar", "y_remote";        | 
[12:24:25]  | updated "y_timers", "y_iter"; MANY     | 
[12:24:25]  | MANY fixes and tweaks in almost every  | 
[12:24:25]  | other library.                         | 
[12:24:25]  |                                        | 
[12:24:25]  |   3.00.0000:                           | 
[12:24:25]  |                                        | 
[12:24:25]  |   YSI 3.0 released!  Now includes the  | 
[12:24:25]  | "y_text" library for better messages,  | 
[12:24:25]  | and a reworked "y_classes" library.    | 
[12:24:25]  | Largely documented here                | 
[12:24:25]  | "http://forum.sa-mp.com/showthread.php | 
[12:24:25]  | ?t=321092".                            | 
[12:24:25]  |                                        | 
[12:24:25]  |   3.01.0002:                           | 
[12:24:25]  |                                        | 
[12:24:25]  |   Small fixes to "y_text" and          | 
[12:24:25]  | "y_classes".                           | 
[12:24:25]  |                                        | 
[12:24:25]  |   3.09.0684:                           | 
[12:24:25]  |                                        | 
[12:24:25]  |   Reverted to old download location.   | 
[12:24:25]  | Improved (and fixed) version checks;   | 
[12:24:25]  | added y_bitmap, y_areas, y_races,      | 
[12:24:25]  | y_zonenames, better documentation;     | 
[12:24:25]  | MANY other bug fixes - see the github  | 
[12:24:25]  | repository for more details:           | 
[12:24:25]  |                                        | 
[12:24:25]  ========================================== 
[12:24:25]  
[12:24:28] [connection] 127.0.0.1:50044 requests connection cookie.
[12:24:29] Incoming connection: 127.0.0.1:50044 id: 0
[12:24:29] [join] Christolis has joined the server (0:127.0.0.1)
Reply
#7

Do a debug that consists in commenting part by part of the code, until you find on which part the server crashes.
Reply
#8

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Do a debug that consists in commenting part by part of the code, until you find on which part the server crashes.
Nice idea dude! Let me try and tell you if I solved my problem and give you the rep then.
Reply
#9

I found the line that causes the crash, removed it temporarily but now it doesnt save my stats when I dissconnect.
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new
        
Query[350],
        
DBResultResult,
        
pName[250],
        
FloatpHealth,
        
FloatpArmour,
        
FloatAngle,
         
Float:    X,
        
Float:  Y,
         
Float:    Z
    
;
    
GetPlayerName(playeridpNamesizeof(pName));
    
GetPlayerPos(playeridXYZ);
    
    
format(Querysizeof(Query), "UPDATE `Accounts` SET Money = '%i', Health = '%f', Armour = '%f', X = '%f', Y = '%f', Z = '%f', Interior = '%f', Angle = '%f' WHERE Name = '%s'",
         
GetPlayerMoney(playerid),
          
GetPlayerHealth(playeridpHealth),
         
GetPlayerArmour(playeridpArmour),
         
XYZ,
          
GetPlayerInterior(playerid),
           
GetPlayerFacingAngle(playeridAngle),
          
DB_Escape(pName));
          
    
Result db_query(DatabaseQuery);
    
    
db_free_result(Result);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)