Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/openal-0.0.8/src/al_error.c @ 17

Last change on this file since 17 was 17, checked in by landauf, 16 years ago

added openal

File size: 2.8 KB
Line 
1/* -*- mode: C; tab-width:8; c-basic-offset:8 -*-
2 * vi:set ts=8:
3 *
4 * al_error.c
5 *
6 * openal error reporting.
7 *
8 */
9
10#include "al_siteconfig.h"
11
12#include <AL/al.h>
13#include <signal.h>
14#include <stdio.h>
15
16#include "al_debug.h"
17#include "al_types.h"
18#include "al_error.h"
19#include "alc/alc_context.h"
20
21/*
22 * _alShouldBombOnError_LOKI controls whether or not _alSetError should
23 * abort when setting an error.  This allows applications to get immediate
24 * error reporting.
25 */
26ALboolean _alShouldBombOnError_LOKI = AL_FALSE;
27
28/*
29 * index2ErrorNo( int index )
30 *
31 * Returns an al error from a simple index.
32 */
33static ALenum index2ErrorNo( int index );
34
35/*
36 * ErrorNo2index( ALenum error_number )
37 *
38 * Returns a simple index from an al error.
39 */
40static int ErrorNo2index( ALenum error_number );
41
42/**
43 * Error support.
44 */
45
46/*
47 * alGetError( void )
48 *
49 * Returns the most recent error generated in the AL state machine.
50 */
51ALenum alGetError( void ) {
52        AL_context *cc;
53        int index;
54
55        _alcDCLockContext();
56
57        cc = _alcDCGetContext();
58
59        if(cc == NULL)
60        {
61                _alcDCUnlockContext();
62                return 0;
63        }
64
65        index = index2ErrorNo(cc->alErrorIndex);
66
67        /*
68         * In deference to the new spec, GetError clears the error
69         * after reading it.
70         */
71        cc->alErrorIndex = 0;
72
73        _alcDCUnlockContext();
74
75        return index;
76}
77
78/*
79 * ErrorNo2index( ALenum error_number )
80 *
81 * Returns a simple index from an al error.
82 */
83static int ErrorNo2index( ALenum error_number ) {
84        switch( error_number ) {
85                case AL_NO_ERROR:
86                        return 0;
87                case AL_INVALID_NAME:
88                        return 1;
89                case AL_INVALID_ENUM:
90                        return 2;
91                case AL_INVALID_VALUE:
92                        return 3;
93                case AL_INVALID_OPERATION:
94                        return 4;
95                case AL_OUT_OF_MEMORY:
96                        return 5;
97                default:
98                        _alDebug( ALD_ERROR, __FILE__, __LINE__,
99                                "Unknown error condition: 0x%x", error_number );
100                        return -1;
101        }
102}
103
104/*
105 * index2ErrorNo( int index )
106 *
107 * Returns an al error from a simple index.
108 */
109static ALenum index2ErrorNo( int index ) {
110        switch( index ) {
111                case 0:
112                        return AL_NO_ERROR;
113                case 1:
114                        return AL_INVALID_NAME;
115                case 2:
116                        return AL_INVALID_ENUM;
117                case 3:
118                        return AL_INVALID_VALUE;
119                case 4:
120                        return AL_INVALID_OPERATION;
121                case 5:
122                        return AL_OUT_OF_MEMORY;
123                default:
124                        _alDebug( ALD_ERROR, __FILE__, __LINE__,
125                                "Unknown index : %d", index );
126                        return -1;
127        }
128}
129
130/*
131 * _alSetError( ALuint cid, ALenum param )
132 *
133 * Sets the error for the context with name cid to param.
134 *
135 * assumes locked context
136 */
137void _alSetError( ALuint cid, ALenum param ) {
138        AL_context *cc;
139
140        cc = _alcGetContext( cid );
141        if(cc == NULL) {
142                /* No default context, no error set. */
143                return;
144        }
145
146        if( cc->alErrorIndex == 0 ) {
147                /*
148                 * Only set error if no previous error has been recorded.
149                 */
150
151                cc->alErrorIndex = ErrorNo2index(param);
152        }
153
154        if(_alShouldBombOnError_LOKI == AL_TRUE) {
155                raise(SIGABRT);
156        }
157
158        return;
159}
Note: See TracBrowser for help on using the repository browser.