Original Post
Building on the previous project click here for reference I've recoded the test1.cpp once again, and it worked perfectly. new test1.cpp on pastebin Then I added the code for HAPI_AllegroCreateBitmap, and now it dies with a segmentation fault. The code that I used is somewhat of a rip from the PyGame sources. I'm not fully certain what it does (I know, I know, never use code that you don't know what it does..I know.), and I'm trying hard to figure it out. This is all a learning experience, and if the Python docs were clear enough for me to understand how this stuff worked, I'd be in better shape. But I'm afraid that after reading the docs over and over, I still cannot make enough sense of the advanced features of extending/embedding to do what I want. I decided to look into the source to Pygame to see how they handle the bitmaps, and so I tried to do the same thing.. sorta. What I expected of the code is the pointer address of an allegro BITMAP to be printed out. Perhaps I am misinterpreting all of this. Any help is greatly appreciated. I know that the problem lies in this code: But I have no clue what I need to do to get the results that I want. Terminal execution result:
int w, h;
PyArg_ParseTuple (pParams, "ii", &w, &h);
BITMAP * test_bmp = create_bitmap (w, h);
#define PyObject_FromBitmap (*(PyObject*(*)(BITMAP*))(void**)PyCObject_AsVoidPtr(PyDict_GetItemString(g_pkHost->m_ptScript->m_pkModuleDictionary, "CreateBitmap")))
return PyObject_FromBitmap (test_bmp);
$ ./HOSTOne
Segmentation fault (core dumped)
script.py
import HostAPI
from Allegro.KeyDefs import *
class Data: pass
def Init():
Data.SCREEN_WIDTH = 800
Data.SCREEN_HEIGHT = 600
Data.SCREEN_DEPTH = 16
Data.FULLSCREEN = 0
HostAPI.SetVideoMode(Data.SCREEN_WIDTH, Data.SCREEN_HEIGHT, Data.SCREEN_DEPTH, Data.FULLSCREEN)
# test should print out the allegro BITMAP pointer address I think
bmpTest = HostAPI.CreateBitmap(128, 128)
print bmpTest
def HandleFrameInput():
HostAPI.PollKeyboard()
if HostAPI.KeyPressed(KEY_ESC): HostAPI.StopHOST()
def RenderFrame():
HostAPI.ClearBuffer()
HostAPI.FlipBuffer()
def HandleFrame():
print 'Random Number from HOST: ', HostAPI.GetRandomNumber(1, 10)
HandleFrameInput()
RenderFrame()
def Main():
count = 0
while True:
count += 1
if count >= 65536: break # testing
HandleFrame()