User Tag List

Results 1 to 6 of 6

Thread: QueryResult inside CPP file crash server?

  1. #1
    Member
    Join Date
    Jul 2016
    Posts
    33
    XP
    370
    Level
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    QueryResult inside CPP file crash server?

    Hey, I'm doing a new system and it requires a Query consult to avoid compile every time I need to add a new ID to the array, so I made a db and I'm getting the data.

    I write:

    Code:
    Item* item = _player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
    QueryResult itemdb = CharacterDatabase.PQuery("SELECT (`id`) FROM `items_prohibidos` WHERE `id`='%s'", item->GetEntry());
    Inside: BattlegrounHandler.cpp

    Code:
    void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData)
    & Player.cpp

    Code:
    InventoryResult Player::CanEquipItem(uint8 slot, uint16 &dest, Item* pItem, bool swap, bool not_loading) const
    BUT!!... When I start the server (it compiles good), I access to my acc and if I wanna create a new player or access to the world with my curren player, Trinity WorldServer.exe crashes.

    (Yes, If a delete this code, WorldServer don't crash).

    Can u help me? Thanks

  2. #2
    Founder <span style='color: #FF4500'>Tommy</span>'s Avatar
    Join Date
    Apr 2013
    Posts
    7,391
    XP
    3,449,104
    Level
    378
    Thanks
    889
    Thanked 1,858 Times in 1,120 Posts
    You need null checks for "item" and "itemdb" variables. Also look at slp's post below as I didn't catch that.

    Example:

    Code:
    Item* item = _player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
    if (item) // If item exists (not null)
    {
        // We can continue our code
        QueryResult itemdb = CharacterDatabase.PQuery("SELECT (`id`) FROM `items_prohibidos` WHERE `id`='%u'", item->GetEntry());
        if (itemdb) // If our query successfully ran (not null)
        {
            // We can continue to do whatever here now
        }
    }

  3. #3
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,497
    XP
    20,134,837
    Level
    500
    Thanks
    1,092
    Thanked 333 Times in 213 Posts
    Quote Originally Posted by zhier View Post
    Code:
    QueryResult itemdb = CharacterDatabase.PQuery("SELECT (`id`) FROM `items_prohibidos` WHERE `id`='%s'", item->GetEntry());
    item->GetEntry() will return a uint32 value not a string value.

    %s = string.
    %u = number.

    Code:
    QueryResult itemdb = CharacterDatabase.PQuery("SELECT (`id`) FROM `items_prohibidos` WHERE `id`='%u';", item->GetEntry());
    that can cause a crash.
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  4. #4
    Founder <span style='color: #FF4500'>Tommy</span>'s Avatar
    Join Date
    Apr 2013
    Posts
    7,391
    XP
    3,449,104
    Level
    378
    Thanks
    889
    Thanked 1,858 Times in 1,120 Posts
    I didn't catch that, rofl. I edited my post and referred yours on that part.

  5. The Following User Says Thank You to Tommy For This Useful Post:


  6. #5
    Mad Scientist <span style='color: #008000'><span class='glow_006400'>slp13at420</span></span>'s Avatar



    Join Date
    Dec 2013
    Location
    Idaho
    Posts
    2,497
    XP
    20,134,837
    Level
    500
    Thanks
    1,092
    Thanked 333 Times in 213 Posts
    lol I cant even count how many times I made this mistake and crash my core during the query also:
    Code:
    
    QueryResult itemdb = CharacterDatabase.PQuery("SELECT (`id`) FROM `characters` WHERE `name`='%s';", player->GetName());
    when it should be :
    Code:
    
    QueryResult charid = CharacterDatabase.PQuery("SELECT `id` FROM `characters` WHERE `name`='%s';", player->GetName().c_str());
    lol

    `!Oh snap forgot to convert it!`
    Achievements:
    Shopper Got a Sticky! Member 1 year registered Level XL Level D
    Awards:
    Pot Head LOL Raffle Winner Top Tagger Donator Hangman Scripter Repacker Drunk Support Member of Staff Da Bomb!
    "Cuz PvP's better with a bag 'o' weed"
    !! King Spade !!

    -Guild Plot System-
    Grumbo'z Guild Warz


    -VIP System-
    Grumbo'z VIP System

  7. #6
    Original Poster
    Member
    Join Date
    Jul 2016
    Posts
    33
    XP
    370
    Level
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Omg Haha what a pity...

    Thanks a lot, it works.

    I didn't knew that about %s and %u.

    This will help me for the rest of my life.

    Solved!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •