0

I Have this struct:

struct BaseLayerComponent {

    //Info
    int posX = -99999;
    int posY = -99999;

    //Texture 
    std::string textureName = NULL_STR;
    std::string localTexture = NULL_STR;
    std::string remoteTexture = NULL_STR;
    std::string remoteTextureParent = NULL_STR;
};

It is store in a custom array class (Actually pointers of this struct are stored).

The class that mainly using it, is WD_MainWorld which inherit from WD_2DWorld

Those two class have a function call Init(), in this function a BaseLayerComponent is created, then we store the ref of this last into the grid (the custom array).

But later when I want to use it, in another function I have a weird bug (Debug function is custom function created for debugging):

systems->ErrSys->Debug(layer0.Grid[X][Y]->textureName);
systems->ErrSys->Debug(layer0.Grid[X][Y]->remoteTexture);

Here the first is working perfectly BUT the second give me an access read violation (Note that I've also tested it with remoteTextureParent but same issue).

So for debugging purpose I've created a funciton called show:

virtual void show() {
    systems->ErrSys->Debug(layer0.Grid[0][0]->remoteTexture);
}

And after a long time of research I've discovered where it started to bug:

this is at the end of the Init function of the parent class (last thing called);

   show();
   return true;
}

here show() works perfectly BUT when we leave the function it stop working:

if (!world->Init())
{
    systems->LastErrMsg = "Main World can't be initialized";
    ErrSubmit(systems->ErrSys, EXO::ERR::LOG_TYPE::ERR, ERR_MAIN_WORLD_INIT, systems->LastErrMsg, "Main World Class - Can't be Initialized");
    return false;
}
else
    world->show();

Remember that textureName still working and I have tested pointer are still good (still the same address).

Thanks, in advance.

UPDATE:

I have changed the show function to test everything:

virtual void show() {

    std::cout << layer0.Grid[0][0] << std::endl;

    std::cout << layer0.Grid[0][0]->posX << std::endl;
    std::cout << layer0.Grid[0][0]->posY << std::endl;

    systems->ErrSys->Debug(layer0.Grid[0][0]->localTexture);
    systems->ErrSys->Debug(layer0.Grid[0][0]->textureName);
    systems->ErrSys->Debug(layer0.Grid[0][0]->remoteTextureParent);
    systems->ErrSys->Debug(layer0.Grid[0][0]->remoteTexture);
}

and here is the Output:

Before the end of Init():

0073EED8
0
0
src/World/DGI_New_Tile_Normal.png
DGI_New_Tile_Normal.png
http://rpg.exodiastudio.com/
TEMP/World/Main/Textures/DGI_New_Tile_Normal.png

After Init():

0073EED8
-858993460
0
  <- There is a space here
  <- and here the error (which is not same as previous, see below):

Unhandled exception at 0x756422A2 in RPGBoards.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0073E784.

UPDATE 2 (For Jabberwocky):

Init in WD_MainWorld: //First we create a EGE world in the main interface (Using connection) EXO::IO::INTERFACES_GAME_TYPE Type = EXO::IO::INTERFACES_GAME_TYPE::GM;

//Creating Builder (What world need);
EXO::TREATEMENT::WORLD::World_Builder Builder;
Builder.background = "black";
Builder.isMovable = true;



//Sending all textures
systems->FTP->CreateFolder(root, 0);
systems->FTP->CreateFolder(root + "Main", 0);
systems->FTP->CreateFolder(root + "Main/Textures", 0);



//Creating default tile
EXO::TREATEMENT::WORLD::BaseLayerComponent comp;
comp.posX = 0;
comp.posY = 0;
comp.localTexture = "src/World/DGI_New_Tile_Normal.png";
comp.textureName = "DGI_New_Tile_Normal.png";

//First we update the online texture path
comp.remoteTexture = root + "Main/Textures/" + comp.textureName;
comp.remoteTextureParent = "http://rpg.exodiastudio.com/";

//now we send texture
bool isDone = false;
systems->FTP->SendFile(comp.localTexture, comp.remoteTexture, 0, &isDone);

while (!isDone);

Builder.baseLayerComponents.push_back(comp);
AddTile(comp);


systems->connection->CallFunction("AddWorld", &Type, &Builder);


show();
return WD_2DWorld::Init();

Init in the parent class WD_2DWorld:

//First we check if systems are active because the class need it
if (systems == nullptr || GC == nullptr)
    return false;


//Creating all layers
for (int i = 1; i <= 9; i++) {
    EXO::TREATEMENT::WORLD::Layer newLayer;
    newLayer.layerLevel = i;
    layers.push_back(newLayer);
}

//set has initialized and return
classInitialized = true;


return true;

0 Answers0