Published by

on

Effect file’s encoding problem

There was a problem which I encountered while I was developing my .net class library for wrapping directx c++ headers. It was about loading effect files and retrieving the effect techniques by direct3d 10 interfaces and functions. Actually I was simply copying the Microsoft’s  direct3d tutorial02 into c# language with the help of my .net directx class library. Everything was the same with that tutorial, even the effect file. At least I was thinking it was 🙂

This is the code part that I converted to c# :

Blob Errors = null;

Result = D3DX10Functions.CreateEffectFromFile(“Tutorial02.fx”, null,

null, “fx_4_0”, ShaderFlags, 0, Device, null, out Effect, out Errors);

if (Result < 0) throw new Exception(

“D3DX10Functions.CreateEffectFromFile has failed : “ + Result);

// Obtain the technique

Technique = Effect.GetTechniqueByName(“Render”);

Result = Technique.GetDescription(out TechniqueDescription);

if (Result < 0) throw new Exception(“GetDescription has failed : “

+ Result);

// Define the input layout

InputElementDescription[] Layout =

{

new InputElementDescription(“POSITION”, 0,

Format.R32G32B32_Float, 0, 0, InputClassification.InputPerVertexData, 0)

};

// Create the input layout

PassDescription PassDescription;

Result = Technique.GetPassByIndex(0).GetDescription(

out PassDescription);

if (Result < 0) throw new Exception(“GetDescription has failed : “

+ Result);

Result = Device.CreateInputLayout(Layout,

PassDescription.IAInputSignature, out VertexLayout);

if (Result < 0) throw new Exception(

“Device.CreateInputLayout has failed : “ + Result);

In here, Result from the CreateEffectFromFile function was not an error code. So, effect file must have been loaded successfuly. Then I was not getting an error from Effect.GetTechniqueByName(“Render”)because its result was a Technique COM interface (a directx interface which is wrapped by a class of my library). The documentation of DirectX 10 states that this function returns null if the technique is not found. But it doesn’t as I understand later on.

At last, Result from Technique.GetPassByIndex(0).GetDescription(out PassDescription) was an invalid argument error code. That was my main problem. I tried to find an answer from the web. I searched many places like directx programming forums but couldn’t find anything similar. I checked my code again and again to make sure that it is the same with Microsoft’s original c++ tutorial. Then I decided to try it in C++ to test it in my project environment . I wrote all code by my hand, line by line in c++ in my project. And the error code was still there. So my directx wrapper class library was innocent. At this point I noticed that the only thing which I didn’t touch in the C++ test was the Effect File !!

Yes, I was still using the same effect file from the C# project. I have copied the effect file from the original tutorial folder to my project folder and BOOM! The error has gone 🙂 I really hate that encoding thing of text files in computers world. You see many letters, words, texts in the screen and you think they reside like that in the disk. But not. You have to remember the encoding factor. The effect file in my C# project was Unicode encoded unwillingly and the original tutorial’s effect file was not Unicode. That difference was the little trouble which drive me to write this post.

I would like to see that Unicode had been a unique standard from the beginning of computers world. I know that old guys didn’t have much resources like we have today. And they were unable to see where the technology can come to in the future. But I really wonder if that was an unthinkable case while they design the coding of writing characters in digital way.

Anyway, There is no explanation about effect files can’t be Unicode in directx documentation or on the internet. At least I couldn’t find one and I wanted to share my research with you. So, there is one explanation now 🙂

The strange detail is in this case, CreateEffectFromFile and Effect.GetTechniqueByName functions doesn’t return any error about the Unicode loaded effect file. But Technique.GetPassByIndex.GetDescription does in some point. It would be great if CreateEffectFromFile warn me about the wrong encoded (Unicode) effect file.

Edit 1 : Code part was updated.

Blog at WordPress.com.