Scope problems?

Hello,


At the moment, I'm working on a university project that uses the OpenNI kinect library, to do image processing.

I'm having the following problem

The code is a modification of an existing project, which works perfectly. It has a series of global variables declared on main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

#include "kinect-stuff.h" // this is just a "simplification". There are many includes
#include "imgProc.h" //my object, imgProc
.
.
.
//globals
DepthGenerator g_depth;
ImageGenerator g_image;

//functions, procedures and main
.
.
.


The class imgProc reunites all the image processing functions. In order to do that, we need to use the global variables in main.cpp, so I did the following.


in imgProc.h
1
2
3
4
5
6
7
8
9
10
11
12
class imgProc
{
private:
	DepthGenerator * _g_depth;
	ImageGenerator * _g_image;

	DepthMetaData  _g_depthMD;
	ImageMetaData  _g_imageMD;

public:
        imgProc(DepthGenerator& dg, ImageGenerator& ig);
        ~imgProc(void);


in imgProc.cpp

1
2
3
4
5
6
7
8
9
10
imgProc::imgProc(DepthGenerator& dg, ImageGenerator& ig){
	_g_depth = &dg;
	_g_image = &ig;
	_g_depth->GetMetaData(_g_depthMD); // CRASH
	_g_image->GetMetaData(_g_imageMD);
}

imgProc::~imgProc(void)
{
}


Now, on main.cpp i do

imgProc p(g_depth, g_image);

The code compiles properly. However, I obtain the following error executing the application

Uncontrolled exception in 0x654ed455 in NiSimpleViewer.exe (The executable file)
: 0xC0000005: access infraction reading 0x00000050

(Sorry if the translation isn't perfect, the error was in spanish )

Thanks in advance for your help
Looks like I can't do this either

(Note :
on imgProc.h i've declared
extern DepthGenerator g_depth;
)

on imgProc.cpp
1
2
3
4
5
6
imgProc::imgProc(DepthGenerator& dg, ImageGenerator& ig){
	_g_depth = &dg;
	_g_image = &ig;
	g_depth.GetMetaData(_g_depthMD); //  Using the global variable instead . I got CRASH
	_g_image->GetMetaData(_g_imageMD);
}



I've also done the following test
 
std::cout << "_g_depth = " << (int) _g_depth << " g_depth = " << (int) &g_depth << "\n";


and both numbers are equal (and not null) , which means I'm not accessing a pointer set to null.

What could be happening here?
Last edited on
First of all, sorry for the tripe post.

Eventually, I decided to scrap the code and work C-style. (no objects. Instead, it's just a library of independent functions)

Not the smartest choice, but I'm in a bit hurry with this project.

If by chance, anybody happens to find the answer, i'd love to hear it.
Topic archived. No new replies allowed.