Re: Native PDB Error

2018-05-29 Thread Begah via Digitalmars-d-learn

On Tuesday, 29 May 2018 at 07:53:49 UTC, rikki cattermole wrote:

On 29/05/2018 7:47 PM, Begah wrote:
I have recently reinstalled a fresh version of Windows 10. I 
installed DMD 1.9.0 and compiled my code ( that was compiling 
before reinstalling Windows ).


What?

That is definitely not a valid dmd version for D2.


Sorry, that was the dub version. I ment 2.080.0


Native PDB Error

2018-05-29 Thread Begah via Digitalmars-d-learn
I have recently reinstalled a fresh version of Windows 10. I 
installed DMD 1.9.0 and compiled my code ( that was compiling 
before reinstalling Windows ).

I get this error at the linking phase :
Native PDB Error: The entry already exists.  The specified module 
already exists


I made a simplified project that gets the same error :

import imageformats;
import derelict.glfw3;

void main() {
IFImage i0;
}

and dub.json :
"dependencies": {
"derelict-glfw3": "4.0.0-beta.1",
"imageformats": "~>7.0.0"
}

Compiling for 32-bit works.
Compiling for 64-bit gives that error : dub --arch=x86_64
Changing imageformats version to 5.2.0 compiles but any higher 
doesn't.
I tried compiling the code with and without admin privileges but 
it doesn't do anything.
I know that PDB is used for debugging but I don't understand this 
error.

Any ideas?


Re: Experimental xml set up

2017-04-02 Thread Begah via Digitalmars-d-learn

On Sunday, 2 April 2017 at 14:15:50 UTC, rikki cattermole wrote:

On 02/04/2017 2:58 PM, Begah wrote:

[...]


Quite out of date.

Here is some code that worked for me:

string raw_input = ...;

auto domBuilder = raw_input
.lexer
.parser
.cursor((CursorError err){})
.domBuilder;
domBuilder.setSource(raw_input);
domBuilder.buildRecursive;
auto dom = domBuilder.getDocument;


Dub/Dmd still complains that there is no property/function 
'lexer' for type string.




Experimental xml set up

2017-04-02 Thread Begah via Digitalmars-d-learn
To load up 3D models in my application, i decided to use the 
COLLADA model format, to do that i need to be able to extract 
information out of an xml file.


Since std.xml is going to be deprecated eventually, is opted to 
try and use std.experiment.xml.


So i created a test project and added this dependency to dub.json 
:

"std-experimental-xml": "~>0.1.2"

I then tried and compiled the exemple i found on the xml wiki at 
https://lodo1995.github.io/experimental.xml/std/experimental/xml.html


Code :
// Made sure I imported Everything
import std.experimental.xml.appender;
import std.experimental.xml.cursor;
import std.experimental.xml.dom;
import std.experimental.xml.domimpl;
import std.experimental.xml.domparser;
import std.experimental.xml.dtd;
import std.experimental.xml.faststrings;
import std.experimental.xml.interfaces;
import std.experimental.xml.lexers;
import std.experimental.xml.parser;
import std.experimental.xml.sax;
import std.experimental.xml.validation;
import std.experimental.xml.writer;
import std.experimental.xml.legacy;
import std.stdio;

void main() {
string input = q"{


   
   The D Programming Language
   A. Alexandrescu
   
   
   Programming in D
   Ali Çehreli
   
   
   Modern C++ Design
   A. Alexandrescu
   

}";

// the following steps are all configurable
auto domBuilder =
input
	   .lexer  // instantiate the best lexer based on 
the type of input
	   .parser // instantiate a parser on top of the 
lexer
	   .cursor // instantiate a cursor on top of the 
parser
	   .domBuilder;// and finally the DOM builder on top of 
the cursor


	// the source is forwarded down the parsing chain and everything 
is initialized

domBuilder.setSource(input);

// recursively build the entire DOM tree
domBuilder.buildRecursive;
auto dom = domBuilder.getDocument;

// find and substitute all matching authors
foreach (author; dom.getElementsByTagName("author"))
   if (author.textContent == "A. Alexandrescu")
   author.textContent = "Andrei Alexandrescu";

// write it out to "catalogue.xml"
auto file = File("catalogue.xml", "w");
file.lockingTextWriter
		.writerFor!string   // instatiates an xml writer on top of an 
output range
		.writeDOM(dom); // write the document with all of its 
children


readln();
}

When trying to compile, i get the following error :
Error: no property 'lexer' for type 'string'

There are also a lot of variable types not recognized by the 
compiler.


Is the wiki example completely outdated or am i missing something?


Alias variable from another class

2016-12-13 Thread Begah via Digitalmars-d-learn

I made a little program to illustrate my confusion :

  import std.stdio;

  class _1 {
  int i;

  this(int n) {
  i = n;
  }
  }

  class _2 {
  _1 instance;

  alias twelve = instance.i;

  this() {
  instance = new _1(12);
  }
  }

  void main() {
  _2 two = new _2();
  writeln(two.instance.i);
  writeln(two.twelve);
  }

What i tried to do is create an alias in class _2 of a variable 
in class _1.

What i would like is :
  two.twelve
to extends to:
  two.instance.i
But the compiler complains it cannot find "this" :
  Error: need 'this' for 'i' of type 'int'

Any ideas?


Re: Shared an non-shared

2016-10-05 Thread Begah via Digitalmars-d-learn
On Wednesday, 5 October 2016 at 12:48:07 UTC, Jonathan M Davis 
wrote:
On Wednesday, October 05, 2016 11:25:57 Begah via 
Digitalmars-d-learn wrote:

[...]


Unless you're writing lock-free algorithms (which really should 
only be done by experts, and even then, they should probably 
reconsider it, since they're so insanely hard to get right), 
_every_ variable/object that's going to be accessible from 
multiple threads needs to be protected by a mutex so that it's 
guaranteed that only one thread accesses the object at a time. 
That would be just as true in C/C++ as it is in D. It's just 
that D requires that they be marked as shared. That being said, 
how many objects should be protected by a given mutex depends 
entirely on what you're doing. In some cases, it makes sense to 
protect a lot of objects with the same mutex (e.g. all of the 
member variables of a class could be protected with a single 
mutex, which is what would happen with synchronized 
functions/classes), and in other cases, it makes sense to have 
as many as a mutex per variable. Having fewer mutexes is easier 
to handle, but it can also mean that code gets blocked waiting 
more. And of course, in some cases, the state in question is 
really spread across multiple variables, and they all need to 
be protected together. I really can't judge how many mutexes 
would be needed without knowing what you're doing.


[...]


Thanks,

Although the triple buffer seems a good idea, there is one 
problem.

I will need three time as much ram than what i currently need.
Not to mention, every time i switch buffer i will need to copy 
all changes made to the updated buffer to the next buffer to be 
updated (Which i think, doing it a few hundred times a second 
might become a bottleneck ).


Re: Shared an non-shared

2016-10-05 Thread Begah via Digitalmars-d-learn
On Wednesday, 5 October 2016 at 07:36:58 UTC, Jonathan M Davis 
wrote:
On Tuesday, October 04, 2016 19:22:10 Begah via 
Digitalmars-d-learn wrote:
How can I make a method that accepts being called by both a 
shared and non-shared object, to prevent having to copy 
methods and adding a "shared"?


You could templatize them, but really, the idea is that you 
_don't_ call much of anything on a shared object. It's not 
thread-safe to do so unless it's protected by a mutex or 
sychronized block. shared is as unwieldy as it is in part 
because it's easy to use incorrectly, and most code should not 
be using shared at all, because the stuff that actually needs 
to be shared across threads is normally pretty minimal.


Thanks for the reply,

One of my problem is that, i need all of my data to be accessible 
by both threads ( I have two ). I am making a 3d application and 
decided to separate the update loop and the render loop ( I just 
created another thread for the update loop meanwhile the render 
loop has to remain on the main thread ).


I just want to ensure that when my render loop ( or update loop ) 
updates/render an object, the other loop cannot ( To avoid 
potential bugs whereas one loop changes the position component 
and the render loop renders the object with only the new x 
position because the y and z variable haven't been changed yet ).


As i will have many of those objects, do i need to create a mutex 
for everyone of them?




Shared an non-shared

2016-10-04 Thread Begah via Digitalmars-d-learn

I seem to be missing something.
It seems that if you want to create a shared object of a 
structure ( or class ), then I have to copy every functions and 
add "shared" to it. This seems way more work than it should.

For example why can't this simply work :

  class Image {
string name;
int contents;

this(string name, int contents) {
this.name = name;
this.contents = contents;
}

void printContents() {
writeln(name, " : ", contents);
}

void changeContents(int newContents) {
this.contents = newContents;
}
  }

  void main()
  {
Image im = new Image("Test", 15);
im.printContents();
im.changeContents(45);
im.printContents();

shared Image imShared = new shared Image("Test2", 80);
imShared.printContents();
imShared.changeContents(6);
imShared.printContents();
  }

How can I make a method that accepts being called by both a 
shared and non-shared object, to prevent having to copy methods 
and adding a "shared"?


I am not looking for an explanation for how to handle 
multi-threading ( synchronization and so on ). I am looking to 
use pre-coded classes and structures ( without using __gshared ) 
with non-shared and shared objects.


Re: Pointer problems, changing for no reasons

2016-06-10 Thread Begah via Digitalmars-d-learn

On Friday, 10 June 2016 at 07:28:44 UTC, Begah wrote:

On Thursday, 9 June 2016 at 19:00:42 UTC, cy wrote:
I can't help but notice that loadModel is not a static member 
function, yet you don't seem to call it with a Model object in 
your "get" function.


Also have a look at std.typecons.RefCounted if you want 
reference counted data..


loadModel is not a method, it is a function. Being a function 
it doesn't have a 'this' so doesn't need to be called with an 
object.
Also, i tried using std.typecons.RefCounted but i didn't like 
the lack of control i had over it ( refCount is private and 
only has a getter method ).


I have found the problem and i still don't understand why i was a 
problem :

struct Model
{
TextureType[] textures;

this(TextureType[] textures...) {
this.textures = textures[];
}
}

In the constructor, i copied the textures to the model's inner 
texture array, and for some reason this caused the problem.

So i needed to change to something like :

this.textures.length = textures.length;
foreach(i; 0..textures.length) {
this.textures[i] = textures[i];
}


Re: Pointer problems, changing for no reasons

2016-06-10 Thread Begah via Digitalmars-d-learn

On Thursday, 9 June 2016 at 19:00:42 UTC, cy wrote:
I can't help but notice that loadModel is not a static member 
function, yet you don't seem to call it with a Model object in 
your "get" function.


Also have a look at std.typecons.RefCounted if you want 
reference counted data..


loadModel is not a method, it is a function. Being a function it 
doesn't have a 'this' so doesn't need to be called with an object.
Also, i tried using std.typecons.RefCounted but i didn't like the 
lack of control i had over it ( refCount is private and only has 
a getter method ).


Pointer problems, changing for no reasons

2016-06-09 Thread Begah via Digitalmars-d-learn
I have a really weird bug in my application, i succeeded in 
making a small program with the bare munimum to show that bug.


The full source code of the application + a dub.json file are at 
https://github.com/Begah/D_Pointer_Problem ( < 300 LOC )


I have a template called ResourceManager (asset.d) which takes in 
an asset ( Texture or Model ) and return a handle to it.
A handle has a pointer to the asset as well as a pointer to an 
integer ( referenceCounter ) both allocated by C's malloc.


First, i call ResourceManager!(Model).get("Coin.obj"). This 
function checks if that resource is already loaded, if not ( and 
in this case it's not ) then it calls model.loadModel();
A model has an array of textures, for simplicity sakes, in this 
example i only add one texture.
Before model.loadModel returns the struct created, i first prints 
the location and value of the referenceCounter of the first 
texture in the model :

Logger.info(model.textures[0].referenceCount);
Logger.info(*model.textures[0].referenceCount);

For example it prints :
	INFO (source\model.d|38) : 597F08 <- Location of the 
referenceCounter
	INFO (source\model.d|39) : 2  <- Value of the 
referenceCounter


Next, model.loadModel return the model structure to 
ResourceManager!(Model).get("Coin.obj") :

AssetType asset = loadFunc(asset_name, args);

static if(is(model.Model == AssetType)) {
Logger.info(asset.textures[0].referenceCount);
Logger.info(*asset.textures[0].referenceCount);
Logger.info(asset.textures[0].referenceCount);
}

And this is where my application, when 
ResourceManager!(Model).get("Coin.obj") prints the location and 
value of the first texture's referenceCounter.

This prints :
	INFO (source\assets.d|83) : 597F08<- Location of the 
referenceCounter
	INFO (source\assets.d|84) : 1 <- Value of the 
referenceCounter
	INFO (source\assets.d|85) : 434A7C<- Location of the 
referenceCounter ( again )


These three lines of code does nothing except prints to the 
console.
As you can see, for some reason, the location of the 
referenceCounter changes for no apparant reason.
I have done many different test and changes but i can't 
understand why this bug is happening, any ideas?


Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Begah via Digitalmars-d-learn

On Monday, 6 June 2016 at 21:25:16 UTC, Alex Parrill wrote:

On Monday, 6 June 2016 at 21:16:18 UTC, Begah wrote:
Does the key of a associative array will be const if the 
reference is requested?


That's probably what it is, actually. Modifying the key with 
the ref could cause the hash of the key to change without the 
hashtable knowing about it, causing it to break.


You might be able to get away with casting the const away, if 
you are sure it won't modify the hash or equality check.


Thanks for the help, i'll just cast away the const


Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-06 Thread Begah via Digitalmars-d-learn
I have a pretty weird error : Error: mutable method 
isolated.graphics.g3d.model.Model.begin is not callable using a 
const object


The weird part is that i do not use const or immutable objects in 
my code ( for the Model ) :

struct Handle {
Model *asset = null;
string asset_name = null;

alias asset this;

@property bool initialized() {
return asset !is null;
}

this(this) {
(*referenceCount)++;
}

~this() {
(*referenceCount)--;
}

size_t *referenceCount;
}

This structure is where the reference is kept ( allocated with 
c's malloc )

Then in my code, i have a loop as such :
ModelInstance[][Handle] instances;

foreach(ref model, ref instances; this.instances) {
model.begin();
foreach(instance; instances) {
instance.render();
}
model.end();
}

But for both model.begin or model.end i get that compilation 
error.


As you can see, i am calling model.begin ( which extends to 
model.asset.begin ) but no const instances are used.


Side note :
When i remove the ref in the for loop :
foreach(model, ref instances; this.instances)

The codes compile and work, i don't understand why being a 
reference or not is a problem.


Re: Using referenceCounters

2016-06-01 Thread Begah via Digitalmars-d-learn

I can see two option but neither of them is really portable :

I can set _store public in std.typecons or i could create a 
setter method.
Neither of these options is portable because i need to directly 
edit the librarie's source code so i can't jump from one computer 
to the next without having those changes.


Using referenceCounters

2016-06-01 Thread Begah via Digitalmars-d-learn
I started using reference counters for my assets in my 
application :

 - Images
 - Models
 - 

Such as :

alias ModelType = RefCounted!Model;

struct Model
{
static ModelType create(Mesh mesh, Shader shader) {
ModelType model = ModelType();

model.mesh = mesh;
model.shader = shader;

return model;
}
}

I worked fine and compiled, but now i also want to keep a 
reference of the created models :

static ModelType[string] loadedModels;

static ModelType load(string modelName) {
ModelType model = null;

switch(extensions) {
case "obj":
model = loadObjModel(modelName, shader);
break;
case "dae":
model = loadColladaModel(modelName);
break;
default: abort(extensions ~ " not supported model file format");
}

	loadedModels[modelName] = model; // This creates a reference, so 
i need to get rid of it

model.refCountedStore()._store._count--; // Something like that
model.modelName = modelName;

return model;
}

So i create load a model, and the reference counter is at one ( 
normal ).
Now i store this model in the associative array but i do not want 
it to count in the reference count. Unfortunatly _store is 
private.
How can i go about making the reference in the associative array 
be canceled?


Re: Garbage Collector : Ignoring a reference

2016-04-26 Thread Begah via Digitalmars-d-learn

On Tuesday, 26 April 2016 at 13:01:26 UTC, ciechowoj wrote:

On Tuesday, 26 April 2016 at 09:07:59 UTC, Begah wrote:
How could i tell the garbage collector to ignore the reference 
in the hashmap and to free it if there isn't any other 
reference that in my hashmap?


You could always zero the reference in the hashmap, as it won't 
be valid after reload anyway...


Nothing will reload.

An example :
I load a texture "button.png" in a class and draw it to the 
screen,
When the screen switches to another screen ie from menu to the 
game,
I want that the "button.png" texture is automaticly destroyed by 
the gc.
But this will never happen because i still have a reference to it 
in my hashmap.
Thus, i need a way to tell the gc to ignore the reference ( or 
something similar ) in that hashmap.


Garbage Collector : Ignoring a reference

2016-04-26 Thread Begah via Digitalmars-d-learn
I am trying to create an asset manager for my textures. I had the 
idea ( it may be a wrong idea ) to create a hashmap of my 
textures with a string as the key. When the program request a 
texture, it firts check if it is in the hashmap and then returns 
if it is :


Texture[string] textures;

Texture loadTexture(string filename) {
  if(filename in textures)
return textures[filename]
  else
// Load image and put it in hashmap
}

Warning : I haven't tested if it actually doesn't work, but 
thinking about it, i think it should not.
My problem is that i return a reference of the texture to the 
program, but i keep one to myself and i want to free the texture 
if my program isn't using it anymore ( no more reference to it ). 
The problem i see, is that i will always have atleast one 
reference to the texture in my hashmap, but i want the garbage 
collector to ignore that reference and to free the texture if 
there are no more references anywhere in my program ( except in 
the hashmap ).


How could i tell the garbage collector to ignore the reference in 
the hashmap and to free it if there isn't any other reference 
that in my hashmap?