Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginner Problem - first OpenGL instruction causes Exception



It looks like you're attempting to issue GL commands while your app is still in the middle of unarchiving its main .nib file (and thus hasn't had the chance to bring up its window, create a CGL context, and bind it to a surface). If you defer your GL calls until -drawRect: (and/or -reshape) you should have better luck.

The demo code you attached might work in the case where the NSOpenGLView subclass is instantiated at runtime (rather than loading the instance from a .nib). But the best practice is to wait until -reshape or -drawRect: to do your GL setup.

---
Troy Stephens
Cocoa frameworks

On Saturday, December 7, 2002, at 11:15 AM, Jens Restemeier wrote:

Hi,

I'm a beginner with both OpenGL and Cocoa, and after playing around with demo code I tried to build my first application from scratch. I subclassed an NSOpenGLView, which is part of an application built in Interface Builder.

The initWithFrame function looks like this (ripped out of demo code):

- (id) initWithFrame:(NSRect)frame {
colorBits = 16;
depthBits = 16;
originalDisplayMode = (NSDictionary *) CGDisplayCurrentMode( kCGDirectMainDisplay );
NSOpenGLPixelFormat *pixelFormat = [ self createPixelFormat:frame ];
if( pixelFormat != nil ) {
self = [super initWithFrame:frame pixelFormat:pixelFormat];
[ pixelFormat release ];
if (self != nil) {
[ [ self openGLContext ] makeCurrentContext ];
glShadeModel( GL_SMOOTH ); // some random OpenGL instruction
}
}
return self;
}

The problem is, I get an EXC_BAD_ACCESS exception as soon as I execute my first OpenGL instruction. (glShadeModel, which I just put there as a test.)
I single-stepped through this code countless times, read through the documentation and compared it to working examples and don't have a clue what I'm doing wrong ! I'm probably missing something obvious...

Thanks,
Jens

P.S.: Crash report:

Date/Time: 2002-12-06 01:46:37 +0000
OS Version: 10.2 (Build 6C115)
Host: Jens-Restemeiers-Computer.local.

Command: MyApp
PID: 14448

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
#0 0x00000000 in 0x0
#1 0x9316162c in -[NSCustomView nibInstantiate]
#2 0x931b9360 in -[NSIBObjectData instantiateObject:]
#3 0x931b9470 in -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:]
#4 0x93237fc4 in loadNib
#5 0x93237c7c in +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:]
#6 0x93237de8 in +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:]
#7 0x932377f4 in +[NSBundle(NSNibLoading) loadNibNamed:owner:]
#8 0x930d253c in NSApplicationMain
#9 0x00003c60 in main (main.mm:13)
#10 0x000039e4 in _start (crt.c:267)
#11 0x00003864 in start

PPC Thread State:
srr0: 0x00000000 srr1: 0x4200f030 vrsave: 0x00000000
xer: 0x00000000 lr: 0x0006c32c ctr: 0x00000000 mq: 0x00000000
r0: 0x00000000 r1: 0xbffff8e0 r2: 0x8fe4c120 r3: 0x00001d01
r4: 0x01db5450 r5: 0x00000000 r6: 0xbffff728 r7: 0x90980354
r8: 0x00000005 r9: 0x000b3298 r10: 0x00000002 r11: 0xa0004544
r12: 0x00000000 r13: 0x00000000 r14: 0x00000000 r15: 0x00000000
r16: 0x002afbd0 r17: 0xa309799c r18: 0xa309799c r19: 0xa309799c
r20: 0xa309799c r21: 0x00000000 r22: 0xa30993e8 r23: 0xa30a109c
r24: 0xa309fcec r25: 0x002b5830 r26: 0x003d7250 r27: 0x002c9510
r28: 0x000b50cc r29: 0x003da520 r30: 0xbffff8e0 r31: 0x003e8230
_______________________________________________
mac-opengl mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-opengl
Do not post admin requests to the list. They will be ignored.

References: 
 >Beginner Problem - first OpenGL instruction causes Exception (From: Jens Restemeier <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.