Sign in to follow this  

[.net] How to create texture array?

This topic is 4354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My texture array is defined and used as follows(I'm using C++): static Direct3D::Texture *meshTextures[] = NULL; . . . meshTextures = new Direct3D::Texture[materials->Length]; I get the following erros when I compile on the above line: e:\Documents and Settings\Wendell\My Documents\Visual Studio Projects\Directx\Meshes\Meshes\Meshes.h(93): error C2691: 'Microsoft::DirectX::Direct3D::Texture' : invalid type for __gc array element e:\Documents and Settings\Wendell\My Documents\Visual Studio Projects\Directx\Meshes\Meshes\Meshes.h(93): error C3149: 'Microsoft::DirectX::Direct3D::Texture' : illegal use of managed type 'Microsoft::DirectX::Direct3D::Texture'; did you forget a '*'? e:\Documents and Settings\Wendell\My Documents\Visual Studio Projects\Directx\Meshes\Meshes\Meshes.h(93): error C2691: 'Microsoft::DirectX::Direct3D::Texture __gc *' : invalid type for __gc array element Why doesn't this work? Is it because I have not supplied a constructor parameters for the Texture object? If so how can I create an array of Texture pointers?

Share this post


Link to post
Share on other sites
Is this VS2005?

You've declared an un-managed array of unmanaged pointers to Direct3D::Textures. Direct3D::Textures is a managed class and so in VS2005, pointers to them should be declared with ^ instead of *

static array<Direct3D::Texture^>^ meshTextures = nullptr;

is how you'd do it in Managed C++ with CLR 2.0

Oh, wait, its the allocation statement that's the problem. You want

meshTexturs = new Direct3D::Texture*[materials->Length];

Or at least that would match the declaration. You declared an array of pointers, then allocatd an array of objects.

Share this post


Link to post
Share on other sites
Well... Thank you... that did stop the compile error.... I'm using VS2003.NET and I would not have guessed that your solution would have worked... Since I may have your attention, I'd like to take the time to ask a few more questions... Is this the best way to declare an array of Texture objects? How can I avoid these types of errors?

Also the background of what I'm doing right now is I'm recreating the C# tutorials in C++. I've been able to overcome all hurdles so far but I do run in to little things like this that seem to stump me.

Share this post


Link to post
Share on other sites
First off, I never had the occasion to use Managed C++ in VS2003/CLR1. Its only in the last few weeks that I found myself with a porting project for which it was a perfect fit. So take whatever I say here with a grain of salt.

What you have to look out for in MC++ is that you can allocate memory both from the system heap and from the gc pool and these two don't mix all that well. My lack of experience, however, with 2003 MC++ doesn't make me very useful for specific advice, though.

But why not just use an ArrayList? The nice people at Microsoft spend all this time making you this gloriously rich runtime. You should use it! :)

[Edited by - dalep on January 11, 2006 3:03:18 PM]

Share this post


Link to post
Share on other sites
I may just do that (use the ArrayList) for my own original directx project development... But for the c++ tutorial projects I just wanted be as close as possible to the c# tutorials... Thanks for your help... I've finished the final tutorial which is the spinning tiger thingy in a window... I'm off to write/convert a c renderer/driver to managed c++...

Share this post


Link to post
Share on other sites

This topic is 4354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this