0

Here is the code:

 public void LoadTexture(string textureId, string path)
    {
        int devilId = 0;
        Il.ilGenImages(1, out devilId);
        Il.ilBindImage(devilId); // set as the active texture

        if (!Il.ilLoadImage(path))
        {
            System.Diagnostics.Debug.Assert(false, "Could not open file, [" + path + "].");
        }
        // The files we'll be using need to be flipped before passing to OpenGL
        Ilu.iluFlipImage();
        int width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH);
        int height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT);
        int openGLId = Ilut.ilutGLBindTexImage();

        System.Diagnostics.Debug.Assert(openGLId != 0);
        Il.ilDeleteImages(1, ref devilId);

        _textureDatabase.Add(textureId, new Texture(openGLId, width, height));
    }

I am getting the Assertion Failed, Could not open file [face.tif] error. I made sure that the face.tif file was in the project folder, solution folder, bin folder, bin\debug folder but still can't open it.

I'm trying to follow the book C# Game Programming for Serious Game Creation.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Liam15
  • 75
  • 1
  • 6

2 Answers2

0

It is looking for the file face.tif in the same directory that your code is running.

What is setting the path that is being passed into the method LoadTexture?

Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
  • In Form1.cs I have a _textureManager.LoadTexture("face", "face.tif"); – Liam15 Jul 11 '13 at 18:42
  • Where is the file `face.tif` in relation to your where your application is running (`.exe`)? – Karl Anderson Jul 11 '13 at 18:43
  • They are both in the bin\debug folder. In other words they are in the same folder – Liam15 Jul 11 '13 at 18:44
  • Have you tried debugging the call to `ilLoadImage()`? Are you using Visual Studio or no? – Karl Anderson Jul 11 '13 at 18:47
  • I am using Visual Studio but I'm very new to it. How do I debug the call to ilLoadImage() – Liam15 Jul 11 '13 at 18:48
  • Without the program running and in the code editor, there is small gutter the left of the actual lines of code, the icon will change when you mouse over this. Clicking in this area will put a red circle on that line, this indicates a break point in your code. Now when you run the application (via Visual Studio F5 or play button), when it hits this line it will break into the code editor and allow you to see values and if you click F11 it will step into the code (in this case it will jump to the code for `ilLoadImage`). – Karl Anderson Jul 11 '13 at 18:57
  • I did that and I hit F11, it jumped down one line which was just "{" then I hit it again and it gave me the same error as before on the line System.Diagnostics.Debug.Assert(false, "Could not open file, [" + path + "].");. I can see that path has the correct value of "face.tif" – Liam15 Jul 11 '13 at 19:02
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33298/discussion-between-karl-anderson-and-liam15) – Karl Anderson Jul 11 '13 at 19:03
-1

On the Form main class (Ex: Form.cs), put these two lines to the top of the constructor:

public Form1(){

    InitializeComponent();
    _openGLControl.InitializeContexts();
YakovL
  • 7,557
  • 12
  • 62
  • 102
  • 1
    does "Ex:" mean "example:"? Please wrap all code bits with backticks, like in my suggested edit (I'm not sure about all the parts because you wrote this in a very short way). Are you sure it's clear to OP what `Form` is and what has it to do with their question? – YakovL Sep 10 '16 at 23:08