• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 3.3.5 Help me fix crash custom code.THX

Shuka

Member
Hello!)
Original code https://github.com/FoxGaming/DPSystem/blob/310d3773fe37e1cd1821fa08a53c8710df1a96a0/dp_system.cpp
Fix fo last trinitycore, fix compile http://pastebin.com/ghUG0QLC
Crash on start up server.
Code:
Program received signal SIGSEGV, Segmentation fault.
0x0000000001a192e4 in ResultSet::Fetch (this=0x0)
    at /home/trinity/TrinityCore/src/server/database/Database/QueryResult.h:40
40	        Field* Fetch() const { return _currentRow; }

Crash gdb http://pastebin.com/yXidsFgg Ubuntu 14.04.
 

Rochet2

Moderator / Eluna Dev
When you make a DB query and there are no rows returned, the query result is null.
You are doing this;
QueryResult testQuery = LoginDatabase.Query("SELECT * from account LIMIT 1;");
if (testQuery->GetFieldCount() < 25)

which will obviously crash when testQuery is null - likely because you have no accounts in the DB at all.
The same idea applies to all of your DB queries.

The solution is to do an additional check like:

if (testQuery)
{
// we had one or more results
}
else
{
// DB is empty or no results match query
}
 

Shuka

Member
When you make a DB query and there are no rows returned, the query result is null.
You are doing this;
QueryResult testQuery = LoginDatabase.Query("SELECT * from account LIMIT 1;");
if (testQuery->GetFieldCount() < 25)

which will obviously crash when testQuery is null - likely because you have no accounts in the DB at all.
The same idea applies to all of your DB queries.

The solution is to do an additional check like:

if (testQuery)
{
// we had one or more results
}
else
{
// DB is empty or no results match query
}
My DB is 5 account.
No't work,crash
Code:
	if (testQuery)
		{
			TC_LOG_INFO("server.loading", "ERROR: Missing coins column.");
			canRun = false;
		}
		else
		{
			TC_LOG_INFO("server.loading", "DP System Loaded Successfully.");
		}
	}
 

Rochet2

Moderator / Eluna Dev
btw, the crashlog is pointing at playet_custom_item.cpp and you gave us dp_system.cpp Are they the same file or is this a mistake?

The crashlog says #1 0x0000000002009cc5 in load_dp::OnStartup (this=0x7fffcae03440) at /home/trinity/TrinityCore/src/server/scripts/Custom/playet_custom_item.cpp:69
but the files you have shared have nothing on line 69. Is there a mistake here somewhere?
 
Top