If GrCreateContext(); is mallocing the memory space and malloc fails, does the returned GrContext variable == NULL or what else would indicate a failure?
Cheers Richard
On Fri, 28 Jul 2000, Mariano Alvarez Fernandez wrote:
If GrCreateContext(); is mallocing the memory space and malloc fails, does the returned GrContext variable == NULL or what else would indicate a failure?
Yes, GrContext returns NULL when it can't do his work.
Doesn't NULL refer to the default context that is created by GrSetMode()? I found this bit a little difficult to decipher in api.doc . If you want to create a subcontext of the default context, don't you pass NULL as a parent pointer? And if you want to set context to the default context, don't you give GrSetContext() a NULL pointer?
J-P
J-P escribió:
On Fri, 28 Jul 2000, Mariano Alvarez Fernandez wrote:
If GrCreateContext(); is mallocing the memory space and malloc fails, does the returned GrContext variable == NULL or what else would indicate a failure?
Yes, GrContext returns NULL when it can't do his work.
Doesn't NULL refer to the default context that is created by GrSetMode()? I found this bit a little difficult to decipher in api.doc . If you want to create a subcontext of the default context, don't you pass NULL as a parent pointer? And if you want to set context to the default context, don't you give GrSetContext() a NULL pointer?
J-P
The normal use is like that:
GrContext *grc;
if( (grc = GrCreateContext( w,h,NULL,NULL )) == NULL ){ process the error } else{ GrSetContext( grc ); do some drawing and probably bitblt to the screen GrSetContext( NULL ); // the screen context! GrDestroyContext( grc ); }
But if you have a GrContext variable (not a pointer) you want to use (probably because is static to some routines) you do:
static GrContext grc; // not a pointer!!
if( GrCreateContext( w,h,NULL,&grc )) == NULL ){ process the error } else{ GrSetContext( &grc ); do some drawing and probably bitblt to the screen GrSetContext( NULL ); // the screen context! GrDestroyContext( &grc ); }
Note that GrDestoryContext know if grc was automatically malloced or no!!
Only if you don't want GrCreateContext use malloc at all, you must allocate the memory buffer and pass it to GrCreateContext.
With GrCreateSubContext is the same, except it don't need the buffer, because it uses the parent buffer, when you use NULL like the parent context, you are using the screen context like the parent (a GRX convention).
Hope this help, M.Alvarez