473,651 Members | 3,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with array initaialization

Hi all,
I have a problem initializing an array of custom structures.
It all occurs trying to visualize solids in XNA (ie new version of
managed directx) but I think the problem resides in something I do
wrong in c#. I really hope not to be off topic, furthermore I'm not a
frequent reader of this newsgroup.

Let's get to the point.

Everything works if I initialize the array in the form:

_Rendervertices = new VertexPositionC oloredNormal[ { value1, value2,
value3 };

whereas if I initialize it like this:

_Rendervertices = new VertexPositionC oloredNormal[3];
_Rendervertices[0] = value1;
_Rendervertices[1] = value2;
_Rendervertices[2] = value2;

I have problems when using the array to fill a vertexbuffer

I believe vertexbuffers read the memory offsets of specified
information and in fact the structure is defined with an attribute
[StructLayout(La youtKind.Sequen tial)] should the array be defined with
some similar attribute as well?

I'm really lost with this. I thought the two methods would result in
the same memory allocation.

Many thanks for any hint you could provide.
Claudio
Jun 27 '08 #1
3 1145
On Jun 3, 4:07 pm, Bonghi <claudio.ben... @gmail.comwrote :
I have a problem initializing an array of custom structures.
It all occurs trying to visualize solids in XNA (ie new version of
managed directx) but I think the problem resides in something I do
wrong in c#. I really hope not to be off topic, furthermore I'm not a
frequent reader of this newsgroup.
No problem - sounds like you've got the right group.
Let's get to the point.

Everything works if I initialize the array in the form:

_Rendervertices = new VertexPositionC oloredNormal[ { value1, value2,
value3 };

whereas if I initialize it like this:

_Rendervertices = new VertexPositionC oloredNormal[3];
_Rendervertices[0] = value1;
_Rendervertices[1] = value2;
_Rendervertices[2] = value2;
Note that you've got value2 twice there - is that in the original
code?

Otherwise, the two snippets should be the same.
I have problems when using the array to fill a vertexbuffer
What kind of problems? Can you post a short but complete program which
demonstrates the problem? See
http://pobox.com/~skeet/csharp/complete.html for what I mean by that.

Jon
Jun 27 '08 #2
On Jun 3, 5:05 pm, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
On Jun 3, 4:07 pm, Bonghi <claudio.ben... @gmail.comwrote :
I have a problem initializing an array of custom structures.
It all occurs trying to visualize solids in XNA (ie new version of
managed directx) but I think the problem resides in something I do
wrong in c#. I really hope not to be off topic, furthermore I'm not a
frequent reader of this newsgroup.

No problem - sounds like you've got the right group.
Let's get to the point.
Everything works if I initialize the array in the form:
_Rendervertices = new VertexPositionC oloredNormal[ { value1, value2,
value3 };
whereas if I initialize it like this:
_Rendervertices = new VertexPositionC oloredNormal[3];
_Rendervertices[0] = value1;
_Rendervertices[1] = value2;
_Rendervertices[2] = value2;

Note that you've got value2 twice there - is that in the original
code?

Otherwise, the two snippets should be the same.
I have problems when using the array to fill a vertexbuffer

What kind of problems? Can you post a short but complete program which
demonstrates the problem? Seehttp://pobox.com/~skeet/csharp/complete.htmlfo r what I mean by that.

Jon
Jon, thanks a lot for replying...
The problem lied somewhere else... I've found the error in a
completely different piece of code and in fact
the two methods I mentioned are perfectly equivalent.

The double value2 was just a typo on this post but the code was
different but too complex for a post so I
modified it to help people have a better understanding.. . of what
turned out to be a false problem.

:)

Many thanks again and apologies for wasting your time.

Claudio
Jun 27 '08 #3
On Jun 3, 6:11 pm, Bonghi <claudio.ben... @gmail.comwrote :
Jon, thanks a lot for replying...
The problem lied somewhere else... I've found the error in a
completely different piece of code and in fact
the two methods I mentioned are perfectly equivalent.
Excellent. It would have been very strange otherwise.

<snip>
Many thanks again and apologies for wasting your time.
No problem at all - just glad it was all sorted out :)

Jon
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3831
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following beautiful script "http://javascript.internet.com/navigation/toolbar-menu.html". It works like a charm. I made my webpage in frames, where the nav-frame shows the menubar, so whenever I click a link in the menubar, it opens in the frame below. But...
1
1534
by: Tony Johansson | last post by:
Hello Experts!! I have two small classes called Intvektor and Matris shown below and a main. Class Intvektor will create a one dimension array of integer by allocate memory dynamically as you can see in the constructor. I know I must have a copy constructor but I have just cut out that just to make it easier for you to read. Class Matris should create a matris by using class Intvektor.
8
15351
by: Brady | last post by:
Hi, I'm having a problem reading and writing to a file. What I'm trying to do is read a file, modify the portion of the file that I just read, and then write the modified data back to the same location in the file. What is happening, is I can read the file, either in entirety or only part of it. And no matter what I try setting the position to, using fsetpos, it always gets set back to the very beginning of the file. I
8
3363
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
8
10706
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type library in the VB6 project, and write the code to call the function that returns the byte array, it works
4
11222
by: daroman | last post by:
Hi Guys, i've problem with my small C++ programm. I've just small template class which represetns a array, everything works fine up to combination with std::string. I did tried it with M$ VC++ and with GCC (Cygwin and Linux) and my problem is when i try do this int main(int argc, char **argv) { array<std::stringa(10); a = "Huhuhu"; <--- with gcc i got a crash !
5
2556
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I use to run a UM program, I kept on getting error messages. I have used someone else's implementation and it runs fine. I have compared my code with other's and I still can't figure it out what's wrong with mine. So please help me out, after 3...
9
2503
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But *after* calling increase_arrays(), I received segmentation fault. I tried to step it through gdb, and I found out that after calling increase_arrays(), words's original value is modified, and if I tried to access it, I get <address 0x11 out of...
25
2346
by: biplab | last post by:
Hi all, I am using TC 3.0..there if I declare a integer array with dimension 162*219...an error msg saying that too long array is shown....what should I do to recover from this problem???
0
8361
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.