On Friday, 1 July 2022 at 13:12:05 UTC, Adam D Ruppe wrote:
On Friday, 1 July 2022 at 12:57:01 UTC, Chris Katko wrote:
Cannot access memory at address 0x10
Looks like an ordinary null pointer. How did you create the
variable?
````D
bool initialize() //called from main
{
g.world = new world_t;
}
class atlasHandler{}
class animation
{
this(int _numFrames, ipair[] coordinates, atlasHandler atlas)
{
}
}
class world_t
{
atlasHandler atlas;
this()
{
viewTest();
atlas = new atlasHandler();
units ~= new elf(pair(200, 200), atlas); //crashes
}
logic()
{
// doesn't crash
units ~= new elf(pair(200, 200), atlas);
}
}
class elf : unit
{
this(pair _pos, atlasHandler atlas)
{
super(0, _pos, pair(0, 0), g.dude_bmp);
// anim = new animation(1, elf_coords, atlas); //doesn't crash
anim = new animation(1, elf_coords, g.world.atlas); //CRASH here
isTreeWalker = true;
}
}
````
also important. it seems to only occur in the constructor. If I
create an elf after the world constructor, it's fine.
...wait, does "world" not 'exist' until after the constructor
finishes? Is that's what's going on? But then why does it 'exist'
when I send it directly? Is it only "registered" with the module
once this() finishes or something like that?