473,473 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
Create 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 CHistogramContainer::appendFrameData(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 2052
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 CHistogramContainer::appendFrameData(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 CHistogramContainer::appendFrameData(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 CHistogramContainer 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
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...
1
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...
6
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...
5
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 ...
0
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...
0
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...
0
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...
8
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: "...
4
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.