Author Topic: Exception when using scripting fn during runtime  (Read 1519 times)

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Exception when using scripting fn during runtime
« on: 8 February 2015, 19:25:29 »

i am using megaglest with my ai engine . i use giveresource function during runtime .it  completes without exception.
when interface updates its status, it generates this exception
\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateProduce [2341] unknown

Please,Could you provide a solution to resolve this exception?
if you need more details i have a screenshot but there's no attachment button here :(

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #1 on: 8 February 2015, 19:54:35 »
AI-engine ?
Written in lua ?

Update: Ok I saw in another thread that you use c++. I need more info, especially the stack trace. It is quite likely that your changes corrupted the memory and cause this kind of error. Is it always the same ?

« Last Edit: 8 February 2015, 20:32:09 by titi »
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #2 on: 8 February 2015, 20:42:06 »
yes i am using c++  scripting functions and this is the details :-
*ERROR* [2015-02-08 19:32:53] In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateProduce 2341] UNKNOWN
*ERROR* [2015-02-08 19:32:53] In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateUnitCommand Line: 439] Error [In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateProduce 2341] UNKNOWN

Stack Trace:
00000000 00000000 00000000 77a25bcc ZwGetContextThread!ntdll (null)(0) +18
00000000 00000000 00000000 77a25bcc ZwGetContextThread!ntdll (null)(0) +18
]
*ERROR* [2015-02-08 19:32:54] In [game.cpp::Glest::Game::Game::update Line: 2785] Error [In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateProduce 2341] UNKNOWN

Stack Trace:
00000000 00000000 00000000 77a25bcc ZwGetContextThread!ntdll (null)(0) +18
00000000 00000000 00000000 77a25bcc ZwGetContextThread!ntdll (null)(0) +18

Stack Trace:
00000000 00000000 00000000 77a25160 ZwGetContextThread!ntdll (null)(0) +18
00000000 00000000 00000000 77a25160 ZwGetContextThread!ntdll (null)(0) +18
]

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #3 on: 9 February 2015, 10:04:30 »
As I don't know what you changed in the code, what is in (..\..\source\glest_game\world\unit_updater.cpp) UnitUpdater::updateProduce in line 2341 for you ? Please show me 10 lines before and after this line here.
« Last Edit: 9 February 2015, 15:02:08 by titi »
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #4 on: 9 February 2015, 23:36:52 »
I didnt change anything in unit_updater
this exception changes every time  i run the script :(
*ERROR* [2015-02-10 00:48:11] In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateHarvest 1804] UNKNOWN error
*ERROR* [2015-02-10 00:48:12] In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateUnitCommand Line: 439] Error [In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateHarvest 1804] UNKNOWN error

Stack Trace:
00000000 00000000 00000000 7813b9c2 ZwGetContextThread!ntdll (null)(0) +18
00000000 00000000 00000000 7813b9c2 ZwGetContextThread!ntdll (null)(0) +18
]
*ERROR* [2015-02-10 00:48:13] In [game.cpp::Glest::Game::Game::update Line: 2785] Error [In [..\..\source\glest_game\world\unit_updater.cpp::Glest::Game::UnitUpdater::updateHarvest 1804] UNKNOWN error

Stack Trace:
00000000 00000000 00000000 7813b9c2 ZwGetContextThread!ntdll (null)(0) +18
00000000 00000000 00000000 7813b9c2 ZwGetContextThread!ntdll (null)(0) +18

Stack Trace:
00000000 00000000 00000000 7813b7ae ZwGetContextThread!ntdll (null)(0) +18
00000000 00000000 00000000 7813b7ae ZwGetContextThread!ntdll (null)(0) +18
]

i added a key press event in game.cpp
void Game::keyPress(SDL_KeyboardEvent c) {
   if(this->masterserverMode == true) {
      return;
   }

   if(gameStarted == false || totalRenderFps <= 0) {
      return;
   }
   try
   {
   if(c.keysym.sym==SDLK_SEMICOLON)
      {
   
          Plan P;
         P.Test(scriptManager);
   

         return;
      }
   }
   catch(const exception &ex) {
         //LogFile::WriteLogFile(ex.what());
         ErrorDisplayMessage(ex.what(),true);
         
   }
   if(currentUIState != NULL) {
      currentUIState->keyPress(c);
      return;
   }

   chatManager.keyPress(c);
}

and here's what i try to execute
void Plan::Test(ScriptManager scriptManager)
{
   try
   {
   LogFile::WriteLogFile("begin testing");
      
   scriptManager.giveResource("gold",0,100);
   }
   catch(const exception &ex) {
      LogFile::WriteLogFile(ex.what());
   }
}

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #5 on: 10 February 2015, 16:54:59 »
I am at work at the moment, but from what I see you call the scriptManager which is for sure not meant to be called form c++. This is the API for the lua scripting language which is maybe not initialized in your case too ( because you are not in a scenario ). So no wonder you crash on different places when you call something not initialized. But I try to look at it in detail.

Maybe you shold start with some lua scenario coding to get familiar with MG?

If you have time come to IRC so we can talk a bit more directly-> see https://megaglest.org/contact
I will be there in 1 or 2 hours too.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #6 on: 10 February 2015, 22:52:16 »
No I am using it inside a scenario beginner 1 . Does lua scripting support real time ?
I need it in real time .any hints ?

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #7 on: 10 February 2015, 22:55:54 »
real time?
You can react on different events and so on. Not sure if this is real time enough for you.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #8 on: 10 February 2015, 23:30:31 »
Yes I need real time as my ai engine is in c++ .my ai engine is multi agent .I need c++ functions to use directly inside my code. Any hints?

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #9 on: 11 February 2015, 09:28:25 »
You must describe a bit more detailed, what kind of AI engine do you have ?
Is it meant to replace the CPU players ? If yes, see how they are attached to the system. see ai_interface.h/cpp in the code.
In general this is here: https://github.com/MegaGlest/megaglest-source/tree/develop/source/glest_game/ai
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #10 on: 11 February 2015, 16:58:46 »
No , I just want functions in c++ like giveresource, createunit , attack,update.....etc. to use them in multiagent architecture in c++ which each agent has a different functionality. No replace for players. I just want to use the main functions of the game . Please,could you mention why this exception happened ?

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #11 on: 11 February 2015, 20:11:54 »
Thats very obvious because you say it crashes at different places. 
Your code must have accessed non allocated memory or corrupted the stack somehow. ( Or maybe you have trouble with threads )
Thats the typical thing when different errors show up.

I have no crystal ball here to know what code changes you made. Do you have a git repository or something where I can access the code ?
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

esraacs

  • Swordman
  • *
  • Posts: 14
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #12 on: 11 February 2015, 22:14:24 »
Do I need when game keypress any event or timer In order to run giveresource ?
I didn't change anything in unit_updater or game source files .

kagu

  • Administrator
  • Horseman
  • ********
  • Posts: 203
    • View Profile
Re: Exception when using scripting fn during runtime
« Reply #13 on: 11 February 2015, 22:23:00 »
You could also join MG chat http://chat.megaglest.org
Megaglest Chat
Please support:
1. CEGUI 2. In-process games 3. Registered Players
Playtime:
Every Sunday 21:00 - 01:00 CET

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,239
    • View Profile
    • http://www.titusgames.de
Re: Exception when using scripting fn during runtime
« Reply #14 on: 11 February 2015, 22:26:16 »
It doesn't matter what you changed in our code if you also have code that may have corrupted the memory.
As alket says, please join the chat for more questions.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios