Access Violation on accessing Class Member Pointers

Hey Everyone!

I am working on a stand alone application that is employs on root gui.
There is apparently something I am doing wrong, but I couldn’t find a similar problem in the forum and now have decided to write a post.
So the problem is that I am trying to add my own classes, and the program compiles, however when I am trying to access any data members of my class(in paticular pointers), even from inside it’s own member functions - I get an exception:

with a call stack:

Note: this behavior doesn’t accrue on constructor calls, only on methods calls or when trying to to assign a value of the public pointer field from another class.
It doesn’t matter if the fields are privet or public. It also doesn’t matter if the pointers are of root types or simple types… like int* or char*.

When generating dictionaries I use: ClassDef(MyClass,0) and ClassImp(MyClass)
and in LinkDef I use: #pragma link C++ class MyClass;

What I have tried:

[quote]- tried to exclude the classes of interest from dictionaries (no generate them at all);

  • tried to use ClassDef(MyClass, 1) 1 instead of 0, because I thought something might be with wrong with a Streamer referencing. (Wild guess)
  • tried to use #pragma link C++ all_function MyClass; #pragma link C++ all_datamember MyClass;
  • tried to Inherit the classes from TNamed / TObject
    …[/quote]
    Non of that works - so I assume I miss out something very basic.

If you could give me a clue to what it is, I would be most grateful :smiley:

Thank you,
Jacob.

Looking at the “location 0x0000000C”, I would say you are trying to access a NULL pointer (i.e. the address of the object for which you are calling this method is “uninitialized” / 0 / NULL).
In your method try to add something like:
if (MyObjectPointer) MyObjectPointer->CallMyMethod();
else { std::cout << “MyObjectPointer is NULL.” << std::endl; }

Hi Jacob,

Without a single line of code, I’m afraid we won’t be able to guess what’s wrong in your application… Could you post a running piece of code showing/reproducing the problem?
And BTW, which version of ROOT? Which platform/compiler?

Cheers, Bertrand.

Yeah, that is my bad, sorry, I forgot to state the obvious :unamused: the pointers are initialised.(Or the should be), but it looks like they are getting lost or deferenced whatever you would call it… and I don’t know how or why. So I thought I has to do with the warning to not use “new MyClass” in a constructor. So that is another thing I have done - I changed it to Initialise the pointers in a separate function call right after instantiation of a class. This also didn’t solve the problem :frowning:

[quote=“bellenot”]Hi Jacob,

Without a single line of code, I’m afraid we won’t be able to guess what’s wrong in your application… Could you post a running piece of code showing/reproducing the problem?
And BTW, which version of ROOT? Which platform/compiler?

Cheers, Bertrand.[/quote]

Hey! Thank you for prompt replies guys! I knew I would miss something out… when composing a post. Root version is root5.34.25 vc++12 Release. I compile with last version of VS2013, on windows 7
/GS included
here is a command line:

I didn’t include the code, just because I was hoping you had encountered the problem before.
Give me an hour- I will try to extract a minimum working code for you to see.

Part of the Code for ROOT Forum.zip (104 KB)
Right, so here I have included a Part of my code. Cleaned most of the methods insides and dereferenced external libraries and dlls. There Is some extra code there - but because I don’t know what the problem is I tried to leave it untouched. If You will run it - just click “Snapshot” on gui and it will brig you to he problem. As you will see the sensorManager is treated as unitialised pointer, though it actually WAS initialsed. Same would happen with any Class Method trying to access it’s classes pointers anywhere in the program.

please let me know what you think or if you need some more information/code cleaning from me to do?

Jacob

Hi Jacob,

First of all, all the signal/slots are wrong. For example:

btnSnapshot->Connect("Clicked()", "UserInterface", this, "Snapshot()"); You try to connect the TGButton::Clicked() signal to the UserInterface::Snapshot() slot. Fine, but you pass ‘this’ pointer as argumet, which is pointing to a MainFrame class. This cannot work! You must pass a pointer pointing to te correct class (in this case to a UserInterface). You should first try to fix those signal/slots, and maybe it will work a bit better… If not, just let me know and send the updated source code.
Hope this helps.

Cheers, Bertrand.

It does! I really appreciate!

I will amend it and let you know, thank you.

The Problem is fixed! Most grateful!

Indeed the slots were the problem. I’m officially stupid :slight_smile:

Thank you, Bertrand!