About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
[Solved] Problem when castin Element of an MemC when more than one inside
Author Message
KraaxLeNain Offline
Member

Post: #1
[Solved] Problem when castin Element of an MemC when more than one inside
Hi,

Using Essenthel 2.0, I'm currently trying to handle NPCS with derived form my Chr class.

I suceed in doing so but it appears, as I store them into an MemC list, that I can't cast them when there is more than two element in my MemC memory. Client crash when using a cast function (cast valid but casted object is unfound/corrupted if I understant right what visual studio gives me during crash).

Details :

In the NPC class how I manage npc storage:
Code:
class NPC : Chr
{
[...]
}
Memc<NPC> npc;

On the game class, in init phase, where I create the NPC
Code:
npc.New().create("Human",Game.ObjParamsPtr(UID(1913893552, 1136375616, 2471945393, 4050012939)),666,Vec(-11.45, 0, 7.9)); //The first NPC
  npc.New().create("Warrior2",Game.ObjParamsPtr(UID(1500814990, 1298568280, 2465897402, 4149338710)),668,Vec(-12, 0, 7.9));//Second NPC spawned at his left

If I spawn only the first NPC, all work I can do with it everything I wish to do...

If I spawn both (or more) well it works until i need to cast one of these obj, like for example when I want to clic on them :
Code:
// move player
      if(Ms.bp(0) && Players.elms()) // on LMB pressed
         if(!Gui.ms() || Gui.ms()==Gui.desktop())
      {
         if(Cur.valid)
         {
            if(Cur.obj.valid())
            {                                                                      
              
             if(Chr *chr=CAST(Chr, &Cur.obj())) //This is where it crash, suceeding the cast but having trouble with values retrieved from it
              {
               Players[0].actionAttack(*chr);
              }
            
            else
            {
               Players[0].actionMoveTo(Cur.pos);
            }
         }
      }
If I suppress all codes involving the cast on these npc I got no crash...
Below a screenshot : me on the left, my two npcs on the right... And the crash when my mouse is on them using the cast...
[Image: 23189_Crash_1.jpg]

I tried to give you what I think are the crucial information to aprehend the problem whithout seeking in all the code I got but if more information or details are needed I'll give them happily.

Have a nice Day.
(This post was last modified: 12-11-2013 09:06 AM by KraaxLeNain.)
12-10-2013 01:04 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Problem when castin Element of an MemC when more than one inside
Hi,

Game objects need to be stored in constant memory address, therefore you should be using Memx instead of Memc.

However the recommended way is to use Game::ObjMemx containers as the tutorials present.
12-10-2013 09:52 AM
Find all posts by this user Quote this message in a reply
KraaxLeNain Offline
Member

Post: #3
RE: Problem when castin Element of an MemC when more than one inside
Ok then I'll try to correct it this night and see if working well (I'll post result).

Question about your answer: is it ok to use Map in this case or not ? Or maybe store it in Memx and then use a map of pointer ? In base code provided with EE2.0, Neighbors seems to be stored in map and not GameObjMemx (or maybe I was mislead in my code analysis).

Thx for the answer !
12-10-2013 10:04 AM
Find all posts by this user Quote this message in a reply
KraaxLeNain Offline
Member

Post: #4
RE: Problem when castin Element of an MemC when more than one inside
Ok so it's working well with MemX, right to the point thanks !
12-11-2013 09:06 AM
Find all posts by this user Quote this message in a reply
Post Reply