summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLieuwe <lieuwemo@gmail.com>2011-03-18 16:23:08 (GMT)
committer Lieuwe <lieuwemo@gmail.com>2011-03-18 16:23:08 (GMT)
commit8b22ca5064d2ea90b1b55d855a8a9b3809fd4137 (patch)
tree3f0acd3f2a5c2af0237bd435f3259b09b998a2b4 /src
parent9c39875ef09d439ef51716dba091188f72977f5e (diff)
downloadpowder-8b22ca5064d2ea90b1b55d855a8a9b3809fd4137.zip
powder-8b22ca5064d2ea90b1b55d855a8a9b3809fd4137.tar.gz
no longer crashes on mangled console.py and other python initialisation errors.
Diffstat (limited to 'src')
-rw-r--r--src/main.c62
-rw-r--r--src/python/tpt_console.py1
2 files changed, 36 insertions, 27 deletions
diff --git a/src/main.c b/src/main.c
index bb02bf1..f176e15 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
diff --git a/src/python/tpt_console.py b/src/python/tpt_console.py
index b26ecef..6654bad 100644
--- a/src/python/tpt_console.py
+++ b/src/python/tpt_console.py
@@ -17,7 +17,6 @@ if(DEBUG==False):
sys.stdout=logger()
sys.stderr=logger()
-
element={"none":0,"dust":1,"watr":2,"oil":3,"fire":4,"stne":5,"lava":6,"gunp":7,
"nitr":8,"clne":9,"gas":10,"plex":11,"goo":12,"icei":13,"metl":14,"sprk":15,
"snow":16,"wood":17,"neut":18,"plut":19,"plnt":20,"acid":21,"void":22,