diff options
| author | Lieuwe <lieuwemo@gmail.com> | 2011-03-18 16:23:08 (GMT) |
|---|---|---|
| committer | Lieuwe <lieuwemo@gmail.com> | 2011-03-18 16:23:08 (GMT) |
| commit | 8b22ca5064d2ea90b1b55d855a8a9b3809fd4137 (patch) | |
| tree | 3f0acd3f2a5c2af0237bd435f3259b09b998a2b4 /src/main.c | |
| parent | 9c39875ef09d439ef51716dba091188f72977f5e (diff) | |
| download | powder-8b22ca5064d2ea90b1b55d855a8a9b3809fd4137.zip powder-8b22ca5064d2ea90b1b55d855a8a9b3809fd4137.tar.gz | |
no longer crashes on mangled console.py and other python initialisation errors.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 62 |
1 files changed, 36 insertions, 26 deletions
@@ -30,6 +30,7 @@ #include "Python.h" #include "pyconsole.h" //#include "pystdlib.h" +char pyready=1; #endif #include <stdio.h> @@ -2090,7 +2091,8 @@ int main(int argc, char *argv[]) { PyErr_Print(); printf("unable to find handle function, mangled console.py?\n"); - return -1; + //return -1; + pyready=0; } pstep=PyObject_GetAttrString(pmodule,"step");//get the handler function @@ -2118,7 +2120,8 @@ int main(int argc, char *argv[]) //sys.stderr PyErr_Print(); printf("unable to find console module, missing file or mangled console.py?\n"); - return -1; + //return -1; + pyready=0; } #else printf("python console disabled at compile time."); @@ -2748,18 +2751,19 @@ int main(int argc, char *argv[]) } } #ifdef PYCONSOLE - if(pkey!=NULL && sdl_key!=NULL) - { - pargs=Py_BuildValue("(c)",sdl_key); - pvalue = PyObject_CallObject(pkey, pargs); - Py_DECREF(pargs); - pargs=NULL; - if(pvalue==NULL) - strcpy(console_error,"failed to execute key code."); - //Py_DECREF(pvalue); - //puts("a"); - pvalue=NULL; - } + if(pyready==1) + if(pkey!=NULL && sdl_key!=NULL) + { + pargs=Py_BuildValue("(c)",sdl_key); + pvalue = PyObject_CallObject(pkey, pargs); + Py_DECREF(pargs); + pargs=NULL; + if(pvalue==NULL) + strcpy(console_error,"failed to execute key code."); + //Py_DECREF(pvalue); + //puts("a"); + pvalue=NULL; + } #endif #ifdef INTERNAL int counterthing; @@ -3660,6 +3664,8 @@ int main(int argc, char *argv[]) if(console_mode) { #ifdef PYCONSOLE + if(pyready==1) + { char *console; //char error[255] = "error!"; sys_pause = 1; @@ -3674,6 +3680,9 @@ int main(int argc, char *argv[]) free(console); if(!console_mode) hud_enable = 1; + } + else + console_mode=0; #else console_mode=0; #endif @@ -3681,18 +3690,19 @@ int main(int argc, char *argv[]) //execute python step hook #ifdef PYCONSOLE - if(pstep!=NULL) - { - pargs=Py_BuildValue("()"); - pvalue = PyObject_CallObject(pstep, pargs); - Py_DECREF(pargs); - pargs=NULL; - if(pvalue==NULL) - strcpy(console_error,"failed to execute step code."); - //Py_DECREF(pvalue); - //puts("a"); - pvalue=NULL; - } + if(pyready==1) + if(pstep!=NULL) + { + pargs=Py_BuildValue("()"); + pvalue = PyObject_CallObject(pstep, pargs); + Py_DECREF(pargs); + pargs=NULL; + if(pvalue==NULL) + strcpy(console_error,"failed to execute step code."); + //Py_DECREF(pvalue); + //puts("a"); + pvalue=NULL; + } #endif sdl_blit(0, 0, XRES+BARSIZE, YRES+MENUSIZE, vid_buf, XRES+BARSIZE); |
