473,769 Members | 5,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

variable initialization results in "unhandled exception"

I'm debugging some code and I have to admit that I don't know yet how
it works.
But I ran into a problem I can't explain
The program is a DLL that retrieves raw data from a camera, builds
histograms based on the pixel values, and displays them on the screen;
here's a small excerpt:

VOID CHistogramConta iner::appendFra meData(WORD *pdwRawData, int nWidth,
int nHeight)
{
int nPixelPos;
__int64 total;
__int64 median;
double accuVar;
for (UINT i = m_nVStart; i <= m_nVEnd; i++) {
for (UINT j = m_nHStart; j <= m_nHEnd; j++) {
// Becareful! pixelval is value of pixel and
// index for distribution as well
int pixelval = *(pdwRawData+(( i-1)*nWidth+j));
The last line always returns an unhandled exception. When I try to see
what value (i-1)*nWidth+j is equal to, it's always the same somewhere
along the lines of -809601 or something (and nWdith always = 1920).
First of all, i starts at 0, so I don't think i-1 is even a valid value
here.

Anyway, what baffles me is that if I create a new variable such as int
pixel = 0; I get an unhandled exception!! If I initialize accuVar to a
value, the initialization does not work!

What is causing this strange behavior, is it a memory issue? How is it
possible to get get an unhandled exception when initializing a
variable? I really know little of how this DLL works, but the trivial
task of adding a variable shouldn't be so bizarre, should it?

Nov 8 '06 #1
2 2082
whiskers wrote:
I'm debugging some code and I have to admit that I don't know yet how
it works.
But I ran into a problem I can't explain
The program is a DLL that retrieves raw data from a camera, builds
histograms based on the pixel values, and displays them on the screen;
here's a small excerpt:

VOID CHistogramConta iner::appendFra meData(WORD *pdwRawData, int nWidth,
int nHeight)
{
int nPixelPos;
__int64 total;
__int64 median;
double accuVar;
for (UINT i = m_nVStart; i <= m_nVEnd; i++) {
for (UINT j = m_nHStart; j <= m_nHEnd; j++) {
// Becareful! pixelval is value of pixel and
// index for distribution as well
int pixelval = *(pdwRawData+(( i-1)*nWidth+j));
The last line always returns an unhandled exception. When I try to see
what value (i-1)*nWidth+j is equal to, it's always the same somewhere
along the lines of -809601 or something (and nWdith always = 1920).
First of all, i starts at 0, so I don't think i-1 is even a valid value
here.

Anyway, what baffles me is that if I create a new variable such as int
pixel = 0; I get an unhandled exception!! If I initialize accuVar to a
value, the initialization does not work!

What is causing this strange behavior, is it a memory issue? How is it
possible to get get an unhandled exception when initializing a
variable? I really know little of how this DLL works, but the trivial
task of adding a variable shouldn't be so bizarre, should it?
It's probably the result of writing beyond your array bounds here or
somewhere else. Doing that results in what the Standard calls undefined
behavior, which can mean anything from nothing to random bad things to
your computer synthesizing a new kind of cheese from dust particles it
has collected. It's really undefined.

The unhandled exception you're talking about is what Microsoft throws
sometimes when you try to access something outside your memory space.
You can catch it with catch(...) or with their __try/__except/__finally
extensions.

Cheers! --M

Nov 8 '06 #2

whiskers wrote:
I'm debugging some code and I have to admit that I don't know yet how
it works.
But I ran into a problem I can't explain
The program is a DLL that retrieves raw data from a camera, builds
histograms based on the pixel values, and displays them on the screen;
here's a small excerpt:

VOID CHistogramConta iner::appendFra meData(WORD *pdwRawData, int nWidth,
int nHeight)
{
int nPixelPos;
__int64 total;
__int64 median;
double accuVar;
for (UINT i = m_nVStart; i <= m_nVEnd; i++) {
for (UINT j = m_nHStart; j <= m_nHEnd; j++) {
I have no idea what your CHistogramConta iner looks like nor what
m_nVEnd is, but typically the "end" of a sequence is one past the last
element. Therefore:

for ( UINT i = m_nVStart; i < m_nVEnd; ++i ) {
for ( UINT j = m_nHStart; j < m_nHEnd; ++j ) {

// Becareful! pixelval is value of pixel and
// index for distribution as well
int pixelval = *(pdwRawData+(( i-1)*nWidth+j));
The last line always returns an unhandled exception. When I try to see
what value (i-1)*nWidth+j is equal to, it's always the same somewhere
along the lines of -809601 or something (and nWdith always = 1920).
First of all, i starts at 0, so I don't think i-1 is even a valid value
here.

Anyway, what baffles me is that if I create a new variable such as int
pixel = 0; I get an unhandled exception!! If I initialize accuVar to a
value, the initialization does not work!

What is causing this strange behavior, is it a memory issue? How is it
possible to get get an unhandled exception when initializing a
variable? I really know little of how this DLL works, but the trivial
task of adding a variable shouldn't be so bizarre, should it?
Nov 8 '06 #3

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

Similar topics

10
4862
by: gregory_may | last post by:
I have an application I created called "JpegViewer.exe". It simply loads a Jpeg file and displays in on the screen. It works great, in my lab. When I am using it at a customer site, things change. Occasionally, it blows up with an Application Exception. It seems to only die at the customer site
1
2001
by: Erialc Berts | last post by:
I know why we get this error, but does anyone know how to catch it so that we can display a more helpful message to our users? I am interested both in a .exe and a web site. Thanks in advance to all positive, helpful replies.
6
2334
by: Paul Steele | last post by:
I often use the following code to check if a program is already running: if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) ... This works find on all of my systems, but a student using one of my programs reported that he was getting an "Unhandled Exception" trying to load my program. This is even stranger since the code in question is in a try/catch block. I took a look at the student's system but...
5
2705
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is return ::memcmp(_First1, _First2, _Count); On inspecting these variables, the strings are in fact equal when the exception occurs and _Count is the right size. As a test I replaced this code in the system include file with a for loop to do the...
0
10168
by: mammucion | last post by:
Trying to automate processing 80,000 data sets through 15 web pages. Application URL creates a new IE instance in which runs first a login form and then runs the rest of the pages in the new window. I can connect to a running Excel instance and obtain information from the Excel DOM. I cannot do the same with Internet Explorer. However, I can successfully create an new IE instance and manipulate it. Using an application that has its own...
0
2674
by: JT | last post by:
This seems like it could be an asp.net bug. I am getting the following exception when I add OnSortCommand attribute to a datagrid. I have deleted the temp directories, rebooted etc and I have isolated it to the OnSortCommands presence. When I use a code behind it doesn't fire any events on the back end and the global error handler grabs it. I put together a very simple example to illustrate the problem below. If anyone has an idea of...
0
2821
by: Gary | last post by:
Trying to install VB6 (learning edition) on Windows XP. When running the SETUP.EXE to install Visual Basic 6.0 it gives the error... "An unhandled win32 exception occured in vs60wiz.exe" or "An unhandled win32 exception occured in setup.exe"
8
1772
joedeene
by: joedeene | last post by:
Hello there, I am having a problem and it is frustrating me because I've been trying to figure it out, and I've even modified the code a few times but the same exception occurs: " 'StackOverflowExcepton' was unhandled " Project Details: Ok, I am creating a text file that will store database information of some customers of mine and I'm using the StreamReader and StreamWriter Class. I can successfully get the information and customer data...
4
3736
by: siddhanta | last post by:
float x = new float; float y = new float; int c=0; using (StreamReader sr = new StreamReader("e: \\CuPeak.dat")) { while (!sr.EndOfStream) {
0
10214
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
10048
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
9996
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
9865
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
7410
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
6674
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();...
0
5304
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
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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.