473,549 Members | 2,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inexplicable System.NullRefe renceException when using stl vector in managed class

Hi,

I've written a managed class that makes use of stl vectors of a few
unmanaged structs for data handling/manipulation, but I'm getting a few
very strange errors. I get an

"Unhandled Exception: System.NullRefe renceException: Object reference
not set to an instance of an object" occasionally when adding a new
element to a vector. By

occasionally I mean that the exact same code works fine most of the
time, throwing the error around 1% of the time. Based on sample data
that I'm feeding the program, the

errors occur on the exact same data every execution, but I don't see
anything wrong with the offending data or the code. Can someone help?
Even if you only have a vague

idea of something I can look into, please let me know.

Here's the relevant code snippet:

// if a headline occurs after a normal paragraph, split the block
there
for (int i = thisDoc->blocks.size( ) - 1; i >= 0; i--)
{
block* curBlock = &thisDoc->blocks[i];
if (curBlock->type == blockType::text )
{
// search through all the paragraphs (from end to start)
bool lastWasHeadline = false;
for (int j = curBlock->paragraphs.siz e() - 1; j >= 0; j--)
{
// is this paragraph a headline?
if (curBlock->paragraphs[j].type == paragraphType:: headline)
lastWasHeadline = true;
else
{
// did we just leave a headline?
if (lastWasHeadlin e)
{
// split the remainder of the block into a new block
block newBlock;
newBlock.type = blockType::text ;
for (int k = curBlock->paragraphs.siz e() - 1; k > j; k--)
{
newBlock.paragr aphs.insert(new Block.paragraph s.begin(),
curBlock->paragraphs[k]);
curBlock->removeParagrap h(k);
}
//!!!!!!!!!!!!!!! !!!ERROR!!!!!!! !!!!!!!!!!!
//Unhandled Exception: System.NullRefe renceException: Object
reference not set to an instance of an object
thisDoc->addBlock(newBl ock);
//!!!!!!!!!!!!!!! !!!ERROR!!!!!!! !!!!!!!!!!!
}
lastWasHeadline = false;
}
}
}
}

From the class header (to show you what my struct declarations look

like):

__nogc struct block
{
rectangle bounds;
rectangle adjacent;
rectangle gutterDist;
int type;
vector<paragrap h> paragraphs;

block()
{
bounds.left = bounds.right = bounds.top = bounds.bottom = 0;
adjacent.left = adjacent.right = adjacent.top = adjacent.bottom =
-1;
gutterDist.left = gutterDist.righ t = gutterDist.top =
gutterDist.bott om = 2147483647;
type = blockType::unde cided;
paragraphs.clea r();
}

~block() {paragraphs.cle ar();}

void addParagraph(pa ragraph newParagraph)
{
// if this is the first line to be added to the paragraph
if (paragraphs.siz e() == 0)
{
bounds.left = newParagraph.bo unds.left;
bounds.right = newParagraph.bo unds.right;
bounds.top = newParagraph.bo unds.top;
bounds.bottom = newParagraph.bo unds.bottom;
}
else
{
if (newParagraph.b ounds.left < bounds.left)
bounds.left = newParagraph.bo unds.left;
if (newParagraph.b ounds.right > bounds.right)
bounds.right = newParagraph.bo unds.right;
if (newParagraph.b ounds.top < bounds.top)
bounds.top = newParagraph.bo unds.top;
if (newParagraph.b ounds.bottom > bounds.bottom)
bounds.bottom = newParagraph.bo unds.bottom;
}
paragraphs.push _back(newParagr aph);
}

void removeParagraph (int index)
{
paragraphs.eras e(paragraphs.be gin() + index);
}
};

__nogc struct page
{
int width, height, resolution;
vector<block> blocks;
double avgLineHeight; // calculated in reFormat(...)

page()
{
width = height = resolution = 0;
blocks.clear();
}

~page() {blocks.clear() ;}

void addBlock(block newBlock) {blocks.push_ba ck(newBlock);}

void removeBlock(int index)
{
blocks.erase(bl ocks.begin() + index);
}
};

// all necessary internal variables
page __nogc* thisDoc;

May 25 '06 #1
0 1327

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

Similar topics

3
9110
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in system.windows.forms.dll
0
2252
by: Yoni Rabinovitch | last post by:
Hi, I am new to C#, so I apologise if this is a stupid question. I have some 3rd party C++ code, which gets built as static libraries (not DLLs). I want to create a C# form, which will call the C++ code. So, I understand that I need to create a Managed C++ Wrapper, for any
11
3723
by: Andreas Wirén | last post by:
Hi I'm a C# .NET newbie doing a minor school project but I'm getting a strange error message. 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object reference not set to an instance of an object." As my references look I seem to be using the old framework(1.0.3705) for this, but re-referencing...
1
1252
by: Klynt | last post by:
Project built using /CLR, but code is old and has not been converted specifically to "managed" (__gc or __value). Everything seemed to work great, until I got the following error. I have a class, let's call it CMyLegacyClass, that has some CString (NOT CString*) member variables. Problem is, when the destructor is called (which actually...
5
555
by: AAguiar | last post by:
I have an asp.net project where the code behind the aspx page calls a c# class which makes calls to a managed static C++ class. The C# class works fine when the asp net worker process starts, when it is invoked by pressing "F5", or when the web.config file is modified. In all these cases the web.config file contains <identity...
8
2908
by: johnmmcparland | last post by:
Hi all, my program is trying to add group boxes with radio buttons at run time. While at one point it was able to draw the group boxes without the radio buttons, now it encounters problems just getting the radiobuttons out of the group box. /// area where radio buttons added to groupbox /// this code is wrapped in another loop creating...
1
2017
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By
1
283
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By
1
1247
by: Bruce | last post by:
I am using VC .NET 2003. I created a simple unmanaged class in C++. The class is contained in a library. I then created a simple managed class wrapper that calls a function in the unmanaged class. I am getting a System.NullReferenceException when instantiating the unmanaged class. What is causing this error? Unmanaged code:
0
7558
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...
0
7484
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...
0
7755
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. ...
0
7997
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...
0
7842
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5400
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...
0
5124
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1974
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
0
798
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.