Obj-C++ EXC_BAD_ACCESS errors...
Could anyone enlighten me as to why I may receive EXC_BAD_ACCESS errors when trying to set member variables of C++ classes? For some reason I cannot access/set any member variables, even if its public/private/protected.
For instance, this will crash:
(in class.h):
public:
bool myBool;
(in class.cpp):
void class::doThis (void)
{
myBool = false; <-- crashes program
}
please someone enlightenme. Also maybe this could be why:
I'm compiling EVERTYHING as Objective-C++.... (but this shouldn't affect anything, as all .cpp files access some ObjC cocoa stuff in one way or another)
For instance, this will crash:
(in class.h):
public:
bool myBool;
(in class.cpp):
void class::doThis (void)
{
myBool = false; <-- crashes program
}
please someone enlightenme. Also maybe this could be why:
I'm compiling EVERTYHING as Objective-C++.... (but this shouldn't affect anything, as all .cpp files access some ObjC cocoa stuff in one way or another)
maaaaark Wrote:Could anyone enlighten me as to why I may receive EXC_BAD_ACCESS errors when trying to set member variables of C++ classes? For some reason I cannot access/set any member variables, even if its public/private/protected.
Uh, did you instantiate the class somehow using new? I'm assuming you're using pointers here.
The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
you're going to need to show us the object's creation.
remember, C++ objects that are members of ObjC classes must be initialized using placement new in the ObjC class' initializer.
remember, C++ objects that are members of ObjC classes must be initialized using placement new in the ObjC class' initializer.
Why do you use C++? Obj-C is built for classes, which is the only pro I can see to using C++ over C.
It's not magic, it's Ruby.
Thank you for bringing that up. I was new-ing child objects, but not the main parent object. I'll blame it on the other developers at work keeping the lights off today... and... the tunnel vision
Wow that is horrible grammar/spelling. It's been a long day (see above
). Why can't you edit replies... only the thread you start? Or am I missing something.
). Why can't you edit replies... only the thread you start? Or am I missing something.
You most certainly can edit replies - look to the bottom right of your post for the 'edit' button.
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Maybe it's not in the aqua theme? I'm not seeing it.
Very strange. It only appears in the very first post. I think I remember this having to do with it only appearing on posts that have titles attached - Carlos?
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
carlos fixed it, but then clearly un-fixed it again :/
If your post does not have a title, then you cannot edit it in the aqua theme. So if you use the 'quick reply' box at the bottom you cannot edit without changing themes. I feel that the quick reply should have a default title (whatever the thread is) but that's just me.
I totally agree with that. Otherwise, it leaves users like me feeling like idiots...
...or maybe that has something to do with something entirely different
...or maybe that has something to do with something entirely different
I am having the same problem.
I found someone saying that was an architecture problem (iPhone is not x86, I think it's ARM) and that you should use a diferent type of alignment, like #pragma options align=something...
I tryed putting the members outside and it works (or set the members to static, also works).
Some ideas?
I found someone saying that was an architecture problem (iPhone is not x86, I think it's ARM) and that you should use a diferent type of alignment, like #pragma options align=something...
I tryed putting the members outside and it works (or set the members to static, also works).
Some ideas?
Hi, sorry for digging up this old thread, but I have the exact same problem and maaaaark's solution didn't help (i.e. I didn't understand what to do).
In my current project I have two C++ classes, Game (which handles all the game calculations) and GameGraphics (which does all the rendering). I also have an ObjC++ class GameView (for the OpenGL view).
GameView has this code:
If I call a method of GameGraphics that accesses member variables, it gives EXC_BAC_ACCESS unless I add "graphics = new GameGraphics();" before using it. That approach works until a method of the GameGraphics calls another one of its methods.
I also tried using placement new, although I'm not sure whether I did it right (it didn't help).
I've been searching the forum and Google to find a proper way to use C++ classes in ObjC++, but I haven't found anything that solves my problem.
(I guess this is in the wrong subforum, but the thread fits my problem.)
In my current project I have two C++ classes, Game (which handles all the game calculations) and GameGraphics (which does all the rendering). I also have an ObjC++ class GameView (for the OpenGL view).
GameView has this code:
Code:
// GameView.h ...
@interface GameView : NSOpenGLView {
...
Game *game;
GameGraphics *graphics;
...
}
@end
// GameView.mm
- (id)init {
if((self = [super init])){
graphics = new GameGraphics();
...
}
...
}I also tried using placement new, although I'm not sure whether I did it right (it didn't help).
I've been searching the forum and Google to find a proper way to use C++ classes in ObjC++, but I haven't found anything that solves my problem.
(I guess this is in the wrong subforum, but the thread fits my problem.)
NSOpenGLView is not initialized by -init. I don't believe your code will be being called at all. Depending on how you have this set up, you'll either be being initialized by -initWithCoder: or by -initWithFrame:; once you figure out which, you'll know where to initialize graphics.

