Skip to content

Commit

Permalink
Revert "Add framebuffer fill function"
Browse files Browse the repository at this point in the history
This reverts commit 3165c53. The issue is that this implementation ends up in a segmentation fault because of unknown reason. The fix will follow in the next commit that implements this function in Python itself.
The bug was, that after filling the framebuffer with one single color, I got a -1 return value of pyfb_flushBuffer function. This is because it says that an error occured when writing to the framebuffer. But when trying to perform any operations to draw to the offscreen buffer, python ends with an segmentation fault. Question is why???
The next commit will replace the original implementation reverted here with implementing the loop in python instead of in C.
  • Loading branch information
RossAdrian committed Aug 5, 2024
1 parent ffd4f0f commit 2097022
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 100 deletions.
30 changes: 0 additions & 30 deletions native/module_pyfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,6 @@ static PyObject* pyfunc_pyfb_sdrawLine(PyObject* self, PyObject* args) {
return PyLong_FromLong(exitcode);
}

/**
* Python wrapper for the pyfb_fill function.
*
* @param self The function
* @param args The arguments, expecting long of the fbnum, long of the color value
*
* @return Just 0
*/
static PyObject* pyfunc_pyfb_sfill(PyObject* self, PyObject* args) {
unsigned char fbnum_c;
uint32_t color_val;

if(!PyArg_ParseTuple(args, "bI", &fbnum_c, &color_val)) {
PyErr_SetString(PyExc_TypeError, "Expecting arguments of type (byte, long)");
return NULL;
}

// now parse the color
struct pyfb_color color;
pyfb_initcolor_u32(&color, color_val);

// and invoke the target function
pyfb_sfill((uint8_t)fbnum_c, &color);

// and return just 0
int exitcode = 0;
return PyLong_FromLong(exitcode);
}

/**
* Python wrapper for the pyfb_drawCircle function.
*
Expand Down Expand Up @@ -297,7 +268,6 @@ static PyMethodDef pyfb_methods[] = {
{"pyfb_drawHorizontalLine", pyfunc_pyfb_sdrawHorizontalLine, METH_VARARGS, "Draw a horizontal line on the framebuffer"},
{"pyfb_drawVerticalLine", pyfunc_pyfb_sdrawVerticalLine, METH_VARARGS, "Draw a vertical line on the framebuffer"},
{"pyfb_drawCircle", pyfunc_pyfb_sdrawCircle, METH_VARARGS, "Draw a circle on the framebuffer"},
{"pyfb_fill", pyfunc_pyfb_sfill, METH_VARARGS, "Fill the framebuffer in one color"},
{"pyfb_flushBuffer", pyfunc_pyfb_flushBuffer, METH_VARARGS, "Flush the offscreen buffer to the framebuffer"},
{"pyfb_getResolution", pyfunc_pyfb_getResolution, METH_VARARGS, "Returns a tupel of the framebuffer resolution"},
{NULL, NULL, 0, NULL}};
Expand Down
37 changes: 0 additions & 37 deletions native/paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,43 +219,6 @@ void pyfb_sdrawCircle(uint8_t fbnum,

pyfb_drawCircle(fbnum, xm, ym, radius, color);

// ready, so return
pyfb_fbunlock(fbnum);
}

void __APISTATUS_internal pyfb_fill(uint8_t fbnum, struct pyfb_color* color) {
struct pyfb_videomode_info vinfo;
pyfb_vinfo(fbnum, &vinfo);

const unsigned long int xres = vinfo.vinfo.xres;
const unsigned long int yres = vinfo.vinfo.yres;

for(unsigned long int iy = 0; iy < yres; iy++) {
// draw a vertical line
pyfb_drawVerticalLine(fbnum, 0, iy, xres, color);
}
}

void pyfb_sfill(uint8_t fbnum, struct pyfb_color* color) {
// first check if fbnum is valid
if(fbnum >= MAX_FRAMEBUFFERS) {
PyErr_SetString(PyExc_ValueError, "The framebuffer number is not valid");
return;
}

// Ok, then lock
pyfb_fblock(fbnum);

// next test if the device is really in use
if(!pyfb_fbused(fbnum)) {
// this framebuffer is not in use, so ignore
PyErr_SetString(PyExc_IOError, "The framebuffer is not opened");
pyfb_fbunlock(fbnum);
return;
}

pyfb_fill(fbnum, color);

// ready, so return
pyfb_fbunlock(fbnum);
}
22 changes: 0 additions & 22 deletions native/pyframebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,28 +442,6 @@ extern void __APISTATUS_internal pyfb_drawCircle(uint8_t fbnum,
unsigned long int radius,
struct pyfb_color* color);

/**
* Fills the complete framebuffer with one color. Setting as color 0x00000000 is
* equivalent to clearing the framebuffer (fill with black).
*
* This is the unsafe version. For the safe one, see the pyfb_sfill function.
*
* @param fbnum The framebuffer number
* @param color The color value
*/
extern void __APISTATUS_internal pyfb_fill(uint8_t fbnum, struct pyfb_color* color);

/**
* Fills the complete framebuffer with one color. Setting as color 0x00000000 is
* equivalent to clearing the framebuffer (fill with black).
*
* This is the safe version. For the unsafe one see the pyfb_fill function.
*
* @param fbnum The framebuffer number
* @param color The color value
*/
extern void pyfb_sfill(uint8_t fbnum, struct pyfb_color* color);

/**
* Paints the content of the offscreen buffer to the framebuffer. This function must be callen
* because this is the only operation that is required to paint the content of the offscreen
Expand Down
11 changes: 0 additions & 11 deletions pyframebuffer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,6 @@ def drawPixel(self, x, y, color):
color = getColorValue(color)
fb.pyfb_setPixel(self.fbnum, x, y, color)

def fill(self, color):
"""
Fills the complete framebuffer with one color. Using as color 0x00000000
or rgba(0, 0, 0, 0) is equivalent to clear the framebuffer (fill the
framebuffer with black).
@param color The color value or Color object
"""
color = getColorValue(color)
fb.pyfb_fill(self.fbnum, color)

def drawLine(self, x1, y1, x2, y2, color):
"""
Draws a line from the Point (x1 | y1) to
Expand Down

0 comments on commit 2097022

Please sign in to comment.