Jump to content
  • Advertisement

Plaristote

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

109 Neutral

About Plaristote

  • Rank
    Newbie
  1. Plaristote

    A prepare that segfault

    Yello ! I'm fixing some pretty serious bugs in my application, and there's only a single one left. I have literally not a single clue nor anything that remotely looks like a clue about what's happening. It's all very very weird to me. I'm almost certain that no one can help me and that I'm doomed. I really don't see how this happened, given that valgrind certified that my application is clean. I have a single error, and that's the one that crashes the game: ==16527== Invalid read of size 4 ==16527== at 0x4FEED5D: asCContext::Prepare(asIScriptFunction*) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x81263EC: StatController::TraitToggled(std::string const&) (statsheet.cpp:270) ==16527== by 0x81327C3: Observatory::Signal<void (std::string const&)>::Observer<StatController>::operator()(std::string const&) (in /home/plaristote/Work/fallout-equestria/build/game) ==16527== by 0x811F0A2: Observatory::Signal<void (std::string const&)>::Emit(std::string const&) (observatory.hpp:196) ==16527== by 0x812B963: StatViewRocket::TraitClicked(Rocket::Core::Event&) (statsheet.cpp:891) ==16527== by 0x813276F: Observatory::Signal<void (Rocket::Core::Event&)>::Observer<StatViewRocket>::operator()(Rocket::Core::Event&) (in /home/plaristote/Work/fallout-equestria/build/game) ==16527== by 0x811DE0E: Observatory::Signal<void (Rocket::Core::Event&)>::Emit(Rocket::Core::Event&) (observatory.hpp:196) ==16527== by 0x811D2B4: RocketListener::ProcessEvent(Rocket::Core::Event&) (rocket_extension.hpp:10) ==16527== by 0x4E04059: Rocket::Core::EventDispatcher::TriggerEvents(Rocket::Core::Event*) (in /usr/lib/libRocketCore.so.1.2.1) ==16527== by 0x4E0428C: Rocket::Core::EventDispatcher::DispatchEvent(Rocket::Core::Element*, Rocket::Core::StringBase<char> const&, Rocket::Core::Dictionary const&, bool) (in /usr/lib/libRocketCore.so.1.2.1) ==16527== by 0x4E4355A: Rocket::Core::Element::DispatchEvent(Rocket::Core::StringBase<char> const&, Rocket::Core::Dictionary const&, bool) (in /usr/lib/libRocketCore.so.1.2.1) ==16527== by 0x4E35119: Rocket::Core::Context::ProcessMouseButtonUp(int, int) (in /usr/lib/libRocketCore.so.1.2.1) ==16527== Address 0xd3e7560 is 0 bytes inside a block of size 332 free'd ==16527== at 0x402A45C: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==16527== by 0x5020EB5: asCScriptFunction::Release() const (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x501431F: asCScriptEngine::CallObjectMethod(void*, asSSystemFunctionInterface*, asCScriptFunction*) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x50143D9: asCScriptEngine::CallObjectMethod(void*, int) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FF2D47: asCGarbageCollector::DestroyOldGarbage() (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FF387F: asCGarbageCollector::AddScriptObjectToGC(void*, asCObjectType*) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x5023291: asCScriptFunction::asCScriptFunction(asCScriptEngine*, asCModule*, asEFuncType) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FF7D30: asCModule::AddScriptFunction(int, int, char const*, asCDataType const&, asCDataType*, asETypeModifiers*, asCString**, int, bool, asCObjectType*, bool, bool, bool, bool, bool, bool, asCString const&) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FA5400: asCBuilder::RegisterScriptFunction(int, asCScriptNode*, asCScriptCode*, asCObjectType*, bool, bool, asCString const&, bool) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FAAC9A: asCBuilder::RegisterNonTypesFromScript(asCScriptNode*, asCScriptCode*, asCString const&) (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FAB1DB: asCBuilder::ParseScripts() (in /usr/lib/libangelscript-2.23.1.so) ==16527== by 0x4FAB639: asCBuilder::Build() (in /usr/lib/libangelscript-2.23.1.so) Followed by an output that isn't from valgrind: pure virtual method called terminate called without an active exception It could be that the context is incorrect. So in doubt I created the context just before calling. It could be that the function pointer is incorrect. So in doubt I re-loaded the function just before the calling as well. I don't understand... what else could it be ? I don't think this is relevant (I would have to post 30 000 lines of code to make it relevant, since the bug doesn't make sense at all... i guess), but here's the code that crashes: void StatModel::ToggleTrait(const string& trait) { Data dtrait = _statsheet["Traits"][trait]; bool is_active = (!dtrait.Nil()) && dtrait == 1; if (_scriptActivateTraits) { string tmp = trait; bool updated; _scriptContext = Script::Engine::Get()->CreateContext(); _scriptActivateTraits = _scriptModule->GetFunctionByDecl("bool ActivateTraits(Data, string, bool)"); _scriptContext->Prepare(_scriptActivateTraits); _scriptContext->SetArgObject(0, &_statsheet); _scriptContext->SetArgObject(1, &tmp); _scriptContext->SetArgByte(2, !is_active); _scriptContext->Execute(); if (_scriptContext->GetReturnByte()) UpdateAllValues(); _scriptContext->Release(); } } I'll take any advice on how to debug this.
  2. Plaristote

    Crash when copying obj_values

    Sweet lord you're right ! I had completly forgotten about those flags (I pretty much went over that part of the documentation because at first I thought only asOBJ_APP_CLASS would be usefull to me). I apologize for my lack of attention. In any way, thank you ! I'm really glad I fell on this AngelScript ! It's a life saver !
  3. Plaristote

    Crash when copying obj_values

    Here they go ! engine->RegisterObjectType (dataClass, sizeof(Data), asOBJ_VALUE | asOBJ_APP_CLASS); engine->RegisterObjectBehaviour(dataClass, asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(asData::Constructor), asCALL_CDECL_OBJLAST); engine->RegisterObjectBehaviour(dataClass, asBEHAVE_DESTRUCT, "void f()", asFUNCTION(asData::Destructor), asCALL_CDECL_OBJLAST); engine->RegisterObjectMethod (dataClass, "const Data& opAssign(const Data &in)", asMETHODPR(Data,operator=, (const Data&), const Data&), asCALL_THISCALL); engine->RegisterObjectMethod (dataClass, "Data& opIndex(string &in)", asMETHODPR(Data,operator[], (const std::string&), Data), asCALL_THISCALL); I tried the explicit call to opIndex and it behaves the same.
  4. Plaristote

    Crash when copying obj_values

    Aha, indeed it works much better that yay ! Thank you ! Now that we're at it, I've got another problem that looks like this one (it crashes in the same fctions) but with opIndex, and I didn't manage to solve it by using references. Problem is I didn't manage to write a short example to reproduce it. This is the opIndex method I registered : engine->RegisterObjectMethod (dataClass, "Data opIndex(string &in)", asMETHODPR(Data,operator[], (const std::string&), Data), asCALL_THISCALL); The operator[] itself returns a copy and that's the whole point (Data is actually a wrapper for a tree, and using copies it allows you to dynamically add branches, or explore branches that don't exist yet). Thus I don't know if it is possible or wise to return Data& on the AS side ? I tried using both these prototypes for AS : "Data opIndex(string)" and "Data& opIndex(string)" : the outcome is the same, but the causes differ. The only way to solve it is to ask AS not to collect garbage on these objects (and that's not really an alternative ^^). If I use Data&, it looks like there's a buffer overload or something like that : because when AS calls my C++ method, it does so with a "this" that has been allocated by scriptstdstring. This is the valgrind output that shows this : ==29662== Invalid read of size 4 ==29662== at 0x80BFCED: std::list<DataBranch*, std::allocator<DataBranch*> >::begin() (stl_list.h:762) ==29662== by 0x80D8124: Data::operator[](std::string const&) (data.cpp:74) ==29662== by 0x4FC0EAA: CallThisCallFunction(void const*, unsigned long const*, int, void (*)()) (in /usr/lib/libangelscript-2.23.1.so) ==29662== by 0xBEB58D3F: ??? ==29662== Address 0xddd94b4 is 0 bytes after a block of size 20 alloc'd ==29662== at 0x402AB64: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==29662== by 0x51126B3: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.17) ==29662== by 0x5114939: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/libstdc++.so.6.0.17) ==29662== by 0x5114A11: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned int, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.17) And if I don't use a reference, I have a double-free problem : ==30274== Invalid free() / delete / delete[] / realloc() ==30274== at 0x402A21C: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==30274== by 0x5021D4D: asCScriptEngine::CallFree(void*) const (in /usr/lib/libangelscript-2.23.1.so) ==30274== by 0x4FC066B: CallSystemFunction(int, asCContext*, void*) (in /usr/lib/libangelscript-2.23.1.so) ==30274== by 0x4FFAC34: asCContext::ExecuteNext() (in /usr/lib/libangelscript-2.23.1.so) ==30274== by 0x4FFB9B7: asCContext::Execute() (in /usr/lib/libangelscript-2.23.1.so) ==30274== by 0x80D5575: Npc::Run(float) (npc.cpp:43) ==30274== by 0x80DACAD: _ZZN5Level7do_taskEvENKUlP10ObjectNodeE_clES1_ (level.cpp:146) ==30274== by 0x80DBB4D: _ZSt8for_eachISt14_List_iteratorIP10ObjectNodeEZN5Level7do_taskEvEUlS2_E_ET0_T_S7_S6_ (stl_algo.h:4442) ==30274== by 0x80DB0E8: Level::do_task() (level.cpp:147) ==30274== by 0x466FC87: AsyncTask::unlock_and_do_task() (in /usr/lib/panda3d/libpanda.so.1.8) ==30274== by 0x10A: ??? ==30274== Address 0x7c993c8 is 4,064 bytes inside a block of size 4,096 alloc'd ==30274== at 0x402B018: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==30274== by 0x4FFBE19: asCContext::Prepare(asIScriptFunction*) (in /usr/lib/libangelscript-2.23.1.so) ==30274== by 0x80DACAD: _ZZN5Level7do_taskEvENKUlP10ObjectNodeE_clES1_ (level.cpp:146) ==30274== by 0x80DBB4D: _ZSt8for_eachISt14_List_iteratorIP10ObjectNodeEZN5Level7do_taskEvEUlS2_E_ET0_T_S7_S6_ (stl_algo.h:4442) ==30274== by 0x80DB0E8: Level::do_task() (level.cpp:147) ==30274== by 0x466FC87: AsyncTask::unlock_and_do_task() (in /usr/lib/panda3d/libpanda.so.1.8) ==30274== by 0x10A: ??? I have good hope that this is the last problem I'll ever have with AS (I already exposed all the interesting parts of my engine's API without issue, that's the last of it : the DataEngine). This one looks a bit trickier than the chicken/egg issue, but I hope therre's enough indication to see where I did wrong ! Can I have help pretty please ?: because when AS calls my C%2
  5. Plaristote

    Crash when copying obj_values

    Greetings ! I would need a bit of help on fixing a problem : apparently I'm doing something wrong when implementing the opAssign operator. Here is a short and easily reproducible piece of code that, for some reason, crashes : struct test { test copy(test other) { std::cout << "test2" << std::endl; thing = other.thing; return (other); } int thing; }; int main(void) { asIScriptEngine* engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); const char* testClass = "Test"; engine->RegisterObjectType (testClass, sizeof(test), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS); engine->RegisterObjectMethod (testClass, "Test opAssign(Test)", asMETHOD(test,copy), asCALL_THISCALL); CScriptBuilder builder; builder.StartNewModule(engine, "testModule"); builder.AddSectionFromFile("scripts/t.as"); builder.BuildModule(); asIScriptModule* module = engine->GetModule("testModule"); asIScriptFunction* func = module->GetFunctionByDecl("void testFunc()"); asIScriptContext* context = engine->CreateContext(); std::cout << "Prepare" << std::endl; context->Prepare(func); std::cout << "Execute" << std::endl; context->Execute(); std::cout << "Done" << std::endl; return (0); } And the AngelScript code : void testFunc() { Test test; Test test2; test = test2; } It crahses at the line "test = test". Can you please help me ?
  6. Plaristote

    Long-time beginner seeking advice

    Maybe it's just a bad heuristic ? It only uses the manhattan distance. So this kind of result doesn't surprise me. This extremly helpfull website ( http://www-cs-students.stanford.edu/~amitp/gameprog.html ) doesn't show any better heuristics for my case : it will always find crappy ways as long as there are obstacles. It proposes to divide the map in regions first to avoid these kind of problem. The thing is, even if the subject of regions is abundantly talked about, no algorithm or explanation about how to do them are provided. I've been trying several time to come up with an algorithm for this, but it's always completly flawed (what is required to know what a region is, what zone does it takes, what pathways connect it to what other region ?). And Googling it, it looks like this website is actually the only one talking about regions in pathfinding algorithm. So, new questions arise : - What kind of heuristic can accuratly calculate the distance between two point when there are obstacles between them ? - If we need to pre-compute regions, how do we find them ?
  7. Greetings ! First, I say long-time beginner because I studied the field (in my free time first, then in school), and I've been developing like half a dozen pathfinding system in the past few years... But I still suck at it. I'm currently developing a RPG, and for the first time I have to concile high-performance with good pathfinding. I usually have only one of them. In the past few months I've been exploring a lot of possibilities, but I'm still stuck : the best solution I found gets exponantially slow with long paths... I think since I'm developing a Fallout-like game (not without the same kind of grid, but with the same kind of walls and obstacles), I'd like to know how they developed theirs. I need my pathfinding to always find the best way. It is acceptable that the pathfinding be limited to a certain distance (I'm pretty sure Fallout's one was). Now what did I try ? I tried A* : the pathfinding is extremly quick whatever happens, but as soon as there are obstacles, the path become far from optimal. Here's an exemple of what my A* would do : - -> empty case b and d -> begin and destination x -> path / -> wall - - - - - - - - - - - - - - - - - - - - - - - - - - - - - b - - - - - - - - - - - - - - - - - - - x - - - - - - - - - - - - - - x x x - - x - - - - - - - - - - - - - x / x - - x - - / - - - - - - - - - - - x / x x x x - - / - - - - - - - - - - x / / / / / / / / / - - - - - - - - - - - x - - - - - - - - - - - - - - - - - - - - x x x d - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This is totally unacceptable. Maybe my implementation of A* is wrong, but I never found any way to implement it better than this. Since I wasn't able to implement a A* that finds an acceptable path, I tried a Dijkstra with limited depth (depth being twice the manhattan distance between the begin and destination points). Dijkstra does find the best path, but it is incredibly slow, especially if I put weight on the arcs (and I had to, otherwise the characters are zigzagging for no purpose). In a zone as little as 10/10, it can loop from 500 to over 4500 times before being certain that it found the best path. A consideration was to use a thread for pathfinding. But this is harder to implement... and somehow, I feel like it's not a good idea. I'm completly stuck. This will be my first 3D serious game, and I can't release it with a poor pathfinding system. I need advice on what kind of pathfinding system I need to implement ? On some of the details, I use some kind of hybrid grid : it's the grid, using arcs to connect the cases that should be connected (this way allow many objects such as doors to disconnect cases from each other). Of course I can change it if there's a better way. Any advices ? What should I do ?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!