Frank Lioty
Frank Lioty

Reputation: 977

struct of bitmaps

I have this struct definition:

public struct Icon {
  public Bitmap bitmap;
  public Bitmap g_bitmap;
  public int bitmap_ID;
  public int g_bitmap_ID;
} 

Icon current = new Icon();

then I tried to load a bitmap from file:

current.bitmap = new Bitmap(path);
//Create the texture
current.bitmap_ID = TexUtil.CreateTextureFromBitmap(current.bitmap);
current.g_bitmap = new Bitmap(current.bitmap)

and the same for the other variables, but bitmap/g_bitmap continue to have null value, bitmap_ID/g_bitmap_ID are at 0.

Not so sure to have understood how a struct work (my previous experience was in C). Tried to read the MSDN documentation but nothing helps.

Upvotes: 1

Views: 409

Answers (1)

Frank Lioty
Frank Lioty

Reputation: 977

Sorry everybody, I'm really a stupid. Forget to pass the reference to my method...

private void Load_Icon(Icon icon, string path) {
  icon.bitmap = new Bitmap(path);
  icon.bitmap_ID = TexUtil.CreateTextureFromBitmap(icon.bitmap);
  icon.g_bitmap = new Bitmap(icon.bitmap);
}

forgotten to add a ref to the first parameter. In this way it works just locally on a copy of icon. This works:

private void Load_Icon(ref Icon icon, string path) [...]

Pardon!

Upvotes: 3

Related Questions