473,666 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inexplicable System.NullRefe renceException when using stl vector

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 24 '06 #1
1 2020
ra*****@hotmail .com wrote:
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

<snip>

The error does not seem to come from the standard features you are
using. It is perhaps because of this "managed" C++. Asking in a
microsoft newsgroup should help you (see
http://www.parashift.com/c++-faq-lit....html#faq-5.9).
Jonathan

May 24 '06 #2

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

Similar topics

3
9130
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
1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
7
8097
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: private void Page_Load(object sender, System.EventArgs e) { // load content XslTransform trans = new XslTransform();
2
7806
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item in treeview i display the content item in axWebBrowser, i close the sub form normally when i close the main the following error is generated An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll ...
1
4085
by: msnews.microsoft.com | last post by:
I'm trying to fill an array of objects but when I add the first object I get a NullReferenceException. ---------------------------------------------------------------------------- ------------------------------------------- Public Class TestClass Public NextSubIndex As Integer = 1 Public arrTestSubClass() As TestSubClass
2
2762
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the Windows domain user account and tried to open the same page which has the databasde query code. When the two user tried to open the same page at the same time, there is a runtime error messsage showing as follows:
8
2915
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 group boxes
0
1338
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
0
8454
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
8362
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,...
1
8560
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,...
0
8644
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6200
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
5671
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2776
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
2
2012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.