• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ tfs 0.4 crash

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
48
so, out fo nowhere this error poped up

terminate called after throwing an istance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_function_call> >' what(): call to empty boost::function

I have no idea what's causing it, I'm using tfs 0.4 and windows, can anyone please please help me?
 
Solution
Follow this to know which lines exactly causes the crash, the only difference is that you'll use Visual studio 2010 or 2012 because you are using TFS 0.4 but it is still exactly same steps.
Follow this to know which lines exactly causes the crash, the only difference is that you'll use Visual studio 2010 or 2012 because you are using TFS 0.4 but it is still exactly same steps.
 
Solution
Follow this to know which lines exactly causes the crash, the only difference is that you'll use Visual studio 2010 or 2012 because you are using TFS 0.4 but it is still exactly same steps.
there are some problem's tho, the server isn't hosted in my machine, there's no visual studio in the host and it would be kinda of a pain actually since the server is already running... since I don't know what's causing the crash, I'll be trying to do what you said and make the crash happen again at my house, dunno if I will be able to tho
 
The host machine is Windows also? If its Linux it will be easier to have crash dump/report.
 
I can't edit my previous coment so I'll just make another one
The crash hadn't happened again, my solution was the following: I was using this source (Fir3element/3777 (https://github.com/Fir3element/3777/)) but for some reason It would always crash on start up so I changed it's exception.cpp and .h with the ones of an older source I had and it worked like a charm, but since the crash happenned I wen't back to fi3element's exception.cpp and .h and the crash haven't happened since then.
I'll be giving Mustafa the best answer since he really helped with the debug idea ;)

@Mustafa1337 in the debug mode, I got the message "creature::updatetilecache out of range" before the terminate called after throwing an istance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_function_call> >' what(): call to empty boost::function
any ideia what it could be? sems like the crash ain't gone..

edit: looking here (otland/tfs-old-svn (https://github.com/otland/tfs-old-svn/blob/master/creature.cpp)) I've found
C++:
void Creature::updateTileCache(const Tile* tile, int32_t dx, int32_t dy)
{
    if((std::abs(dx) <= (mapWalkWidth - 1) / 2) &&
        (std::abs(dy) <= (mapWalkHeight - 1) / 2))
    {
        int32_t x = (mapWalkWidth - 1) / 2 + dx;
        int32_t y = (mapWalkHeight - 1) / 2 + dy;

        localMapCache[y][x] = (tile && tile->__queryAdd(0, this, 1,
            FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RET_NOERROR);
    }
#ifdef [B]DEBUG[/B]
    else
        std::cout << "Creature::updateTileCache out of range." << std::endl;
#endif
}

may be a monster dying to fire?

on my sources I have the following code:
C++:
void Creature::updateTileCache(const Tile* tile)
{
    if(isMapLoaded && tile->getPosition().z == getPosition().z)
        updateTileCache(tile, tile->getPosition());
}

void Creature::updateTileCache(const Tile* tile, int32_t dx, int32_t dy)
{
    if((std::abs(dx) <= (mapWalkWidth - 1) / 2) && (std::abs(dy) <= (mapWalkHeight - 1) / 2))
    {
        int32_t x = (mapWalkWidth - 1) / 2 + dx, y = (mapWalkHeight - 1) / 2 + dy;
        localMapCache[y][x] = (tile && tile->__queryAdd(0, this, 1,
            FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RET_NOERROR);
    }
#ifdef [B]DEBUG[/B]
    else
        std::clog << "Creature::updateTileCache out of range." << std::endl;
#endif
}
}
edit: I think I might know what the problem is, a creature is trying to spawn without having room to do so, and when that happens the source is trying to find another location for the creature, but only loking to x position, the first code I mentioned also looks for Y
C++:
int32_t y = (mapWalkHeight - 1) / 2 + dy;
I'll add that and see if it fixes the problem, will take time to know for sure tho since it's hard to make the crash happen

edit: Just happened again.. I'm back to my original creature.cpp: //////////////////////////////////////////////////////////////////////// // Ope - Pastebin.com (https://pastebin.com/GtKsKVHz) I'll try to adapt some stuff from otx to see if it will fix the issue... dunno, I'm really out of ideas
 
Last edited by a moderator:
Can you try adding this instead of yours, I got it from a fixed TFS 0.4 rev 3884, You should have 3 updateTileCache so remove them all and add these ones.
C++:
void Creature::updateTileCache(const Tile* tile, int32_t dx, int32_t dy)
{
    if((std::abs(dx) <= (mapWalkWidth - 1) / 2) && (std::abs(dy) <= (mapWalkHeight - 1) / 2))
    {
        int32_t x = (mapWalkWidth - 1) / 2 + dx, y = (mapWalkHeight - 1) / 2 + dy;
        localMapCache[y][x] = (tile && tile->__queryAdd(0, this, 1,
            FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RET_NOERROR);
    }
#ifdef [B]DEBUG[/B]
    else
        std::clog << "Creature::updateTileCache out of range." << std::endl;
#endif
}

void Creature::updateTileCache(const Tile* tile, const Position& pos)
{
    const Position& myPos = getPosition();
    if(pos.z == myPos.z)
        updateTileCache(tile, pos.x - myPos.x, pos.y - myPos.y);
}

void Creature::updateTileCache(const Tile* tile)
{
    if(isMapLoaded && tile->getPosition().z == getPosition().z)
        updateTileCache(tile, tile->getPosition());
}
 
I just setted up that crash dump thing in my live server, once it crashes I'll know exactly what's hapenning so I might use this code of yours, thank you. I'll post here once the server eventually crashes again

Exception thrown at 0x00681227 in TheForgottenServer.exe: 0xC0000005: Access violation reading location 0xF35A1810.
Unhandled exception at 0x00681227 in TheForgottenServer.exe: 0xC0000005: Access violation reading location 0xF35A1810.
1566759480377.png
it said "no source code availabe" even tho the code was loaded and open in vs, any idea?

I think i could create a new exception for this issue, but any idea how to?
 
Try running as Administrator and get sure you loaded the same source files for TFS version you are using.
 
Aight, I changed the updateTileCache thing in creature.cpp, re-compiled and now I'm running VS and TFS as admin, let's wait

edit: just crashed again
1566765882817.png
Unhandled exception at 0x00648151 in TheForgottenServer.exe: 0xC0000005: Access violation reading location 0x5736B000.

1566765947472.png
nothing being ponted in the source code and I'm using the currect sources, opened VS and TFS as admin. Here's the dmp file informations
1566766228733.png
1566766262145.png
1566766332810.png

edit: A friend of mine just told me that it ain't showing the code because on my linkers I have -O1 and -s, I removed them, recompiled and now I'll put the server back online again..
 
Last edited:
Aight it's been some time since the last crash, ever since I removed -O1 and -s from my linkers and changed a weapon script that had target declared
Lua:
target
to
Lua:
local target
it stopped crashing. I saw a comment of a guy saying that access violation happens when you try to read or change a value that's not on the memory anymore, and having that target as somewhat global was maybe causing problems
it's eithar that target thing or simply removing the -O1 and -s solved the thing, a friend of mine told that once he removed -O and -s from a code and it stopped crashing
if anyone come accross the same problem, loke for your scripts if you ain't using a global value that will be changing, also remove -O and -s before debugging

nvm, just happened again...
1566921891462.png
again, running vs and tfs as admin and it will still not show me error in the source
 
nvm, just happened again...
View attachment 38600
again, running vs and tfs as admin and it will still not show me error in the source
After you compiled, is there a pdb file? It seems that there isn't or it's not being loaded by the debugger.
If you do have one, look here: Set symbol (.pdb) and source files in the debugger - Visual Studio (https://docs.microsoft.com/en-us/visualstudio/debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger?view=vs-2017)
 
na I don't have that, maybe it's because I compiled using devcpp? I'll try compiling with vs and then setting the debug thing up again
 
Yeah, I was wondering if you even compiled 0.4 with VS. DevCPP will not generate any debug information for you (I don't even think it has a debugger). And compiling 0.4 with VS with no pre-made solution you'll have to deal with all the libs yourself in order to compile.
Why are you still using 0.4 anyways?
 
well it does what I need it to do just fine, this is the only problem I have with the source and it's probably a lua script thing that's causing it. Also, my serv is already kinda big so if I go to that tfs 1.2 for 8.6 a lot of stuff might break
 
well it does what I need it to do just fine, this is the only problem I have with the source and it's probably a lua script thing that's causing it. Also, my serv is already kinda big so if I go to that tfs 1.2 for 8.6 a lot of stuff might break
It does just fine for now, but what about in the future when you have more bugs, or any features from newer versions you want to implement? You're already going to have problems attempting to debug anything now & in the future as well. Converting an entire datapack is barely even a few days work at most, considering most of what you've added to your source is already in newer versions or has equivalent code.
From my point of view, it's like you're still using Windows 1995 while we're all on Windows 10.
Believe me, I was the exact same way until I tried TFS 1.2 (which was in development at the time) and saw how much easier things were & never went back.
You're free to keep using 0.4 as you wish, but I'm just trying to let you know that there's a reason people are moving forward, the new engines are much more flexible and cleaner than 0.4 is. And I wouldn't be surprised to see that support for anything pre-1.0 is halted.
 
you know what, I'll start using that 1.3 tfs from nekiro
thing is, until I finish converting that I'll still need to keep my server running so I really need to debug this now
 
you know what, I'll start using that 1.3 tfs from nekiro
thing is, until I finish converting that I'll still need to keep my server running so I really need to debug this now
So then you'll have to manually add each file to a new solution in VS, add the libs required to compile in project->properties->additional include directories (for including .h files) and protject->properties->linker->additional library directories (.lib files), add the libraries to linker->additional libraries to link them. Keep trying to compile and deal with each lib file that says can't be found one at a time, google for the libs if need be.
 
aight I managed to debug the thing and I had changed previously in my game.cpp file
C++:
Thing* thing = internalGetThing(player, fromPos, fromIndex, spriteId, STACKPOS_MOVE);
    Cylinder* toCylinder = internalGetCylinder(player, toPos);
if(!thing || !toCylinder)
    {
        player->sendCancelMessage(RET_NOTPOSSIBLE);
        return false;
    }
to
C++:
Thing* thing = internalGetThing(player, fromPos, fromIndex, spriteId, STACKPOS_MOVE);
    Cylinder* toCylinder = internalGetCylinder(player, toPos);
if(toCylinder->getTile()->getItemCount() > 130)
    {
     player->sendCancelMessage(RET_NOTPOSSIBLE);
     return false;
     }
I changed it back to the default (fist code I mentioned) and I think it will fix the crases. The cange I had made was to prevent a absurd amount of items in a single sqm, but since I removed clean from my globalevents things wre stacking up to that 150 and then crashing idk
 
Last edited:
Any time you're attempting to use a pointer, you need to check if it exists beforehand, otherwise you'll eventually get a segfault.
C++:
if (toCylinder) {
    Tile* tile = toCylinder->getTile();
    if (tile && tile->getItemCount() >= 130) {
        player->sendCancelMessage(RET_NOTPOSSIBLE);
        return false;
    }
}
 
Back
Top