Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightingDemo, SlimDX Error #5

Open
GrimGX opened this issue Feb 23, 2016 · 1 comment
Open

LightingDemo, SlimDX Error #5

GrimGX opened this issue Feb 23, 2016 · 1 comment

Comments

@GrimGX
Copy link

GrimGX commented Feb 23, 2016

Hi Eric,

Thanks for the awesome code, it is really helping me make the move from XNA.

I am having a small issue in the LightDemo project, perhaps you can explain why.

In the DrawScene method you have the following code:

var array = Util.GetArray(_dirLight);
_fxDirLight.SetRawValue(new DataStream(array, false, false), array.Length);

All is well until it tries to set the array as "Util.GetArray(_pointLight)" and call _fxPointLight.SetRawValue()

At the SetRawValue call an object reference error is thrown by SlimDX.

I looked it up and came across that section of the tutorial. Someone left a comment there saying that they had a similar issue and that they resolved if by initializing a new array with the size [1024] for each of these calls. I tried that and it did not work (Same Error).

Please let me know if you can help and thanks again for the awesome tutorials.

Regards,
George

@vicdxxx
Copy link

vicdxxx commented May 5, 2019

Hi, @ericrrichards
Are you solve this problem?
I found a way bypass this problem, just modify byte array length to suit actual size:
public static byte[] GetArray(object o) {
var len = Marshal.SizeOf(o);
_unmanagedStaging = new byte[len];
Array.Clear(_unmanagedStaging, 0, _unmanagedStaging.Length);
if (len >= _unmanagedStaging.Length) {
_unmanagedStaging = new byte[len];
}
var ptr = Marshal.AllocHGlobal(len);
Marshal.StructureToPtr(o, ptr, true);
Marshal.Copy(ptr, _unmanagedStaging, 0, len);
Marshal.FreeHGlobal(ptr);
return _unmanagedStaging;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants