bugfix: segfault due to use of uninitialized Vector class reference
This commit is contained in:
parent
d2e4791f5a
commit
02c512402e
2 changed files with 78 additions and 54 deletions
|
|
@ -50,8 +50,16 @@ PyClickCallable::PyClickCallable()
|
|||
|
||||
void PyClickCallable::call(sf::Vector2f mousepos, std::string button, std::string action)
|
||||
{
|
||||
// Create a Vector object for the position
|
||||
PyObject* pos = PyObject_CallFunction((PyObject*)&mcrfpydef::PyVectorType, "ff", mousepos.x, mousepos.y);
|
||||
// Create a Vector object for the position - must fetch the finalized type from the module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (!vector_type) {
|
||||
std::cerr << "Failed to get Vector type for click callback" << std::endl;
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
return;
|
||||
}
|
||||
PyObject* pos = PyObject_CallFunction(vector_type, "ff", mousepos.x, mousepos.y);
|
||||
Py_DECREF(vector_type);
|
||||
if (!pos) {
|
||||
std::cerr << "Failed to create Vector object for click callback" << std::endl;
|
||||
PyErr_Print();
|
||||
|
|
|
|||
|
|
@ -686,8 +686,11 @@ UIDrawable* UIGrid::click_at(sf::Vector2f point)
|
|||
|
||||
// Only fire if within valid grid bounds
|
||||
if (cell_x >= 0 && cell_x < this->grid_x && cell_y >= 0 && cell_y < this->grid_y) {
|
||||
// Create Vector object for cell position
|
||||
PyObject* cell_pos = PyObject_CallFunction((PyObject*)&mcrfpydef::PyVectorType, "ff", (float)cell_x, (float)cell_y);
|
||||
// Create Vector object for cell position - must fetch finalized type from module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (vector_type) {
|
||||
PyObject* cell_pos = PyObject_CallFunction(vector_type, "ff", (float)cell_x, (float)cell_y);
|
||||
Py_DECREF(vector_type);
|
||||
if (cell_pos) {
|
||||
PyObject* args = Py_BuildValue("(O)", cell_pos);
|
||||
Py_DECREF(cell_pos);
|
||||
|
|
@ -703,6 +706,7 @@ UIDrawable* UIGrid::click_at(sf::Vector2f point)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -715,8 +719,11 @@ UIDrawable* UIGrid::click_at(sf::Vector2f point)
|
|||
|
||||
// Only fire if within valid grid bounds
|
||||
if (cell_x >= 0 && cell_x < this->grid_x && cell_y >= 0 && cell_y < this->grid_y) {
|
||||
// Create Vector object for cell position
|
||||
PyObject* cell_pos = PyObject_CallFunction((PyObject*)&mcrfpydef::PyVectorType, "ff", (float)cell_x, (float)cell_y);
|
||||
// Create Vector object for cell position - must fetch finalized type from module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (vector_type) {
|
||||
PyObject* cell_pos = PyObject_CallFunction(vector_type, "ff", (float)cell_x, (float)cell_y);
|
||||
Py_DECREF(vector_type);
|
||||
if (cell_pos) {
|
||||
PyObject* args = Py_BuildValue("(O)", cell_pos);
|
||||
Py_DECREF(cell_pos);
|
||||
|
|
@ -730,6 +737,7 @@ UIDrawable* UIGrid::click_at(sf::Vector2f point)
|
|||
Py_DECREF(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Don't return this - no click_callable to call
|
||||
}
|
||||
}
|
||||
|
|
@ -2248,8 +2256,11 @@ void UIGrid::updateCellHover(sf::Vector2f mousepos) {
|
|||
if (new_cell != hovered_cell) {
|
||||
// Fire exit callback for old cell
|
||||
if (hovered_cell.has_value() && on_cell_exit_callable) {
|
||||
// Create Vector object for cell position
|
||||
PyObject* cell_pos = PyObject_CallFunction((PyObject*)&mcrfpydef::PyVectorType, "ff", (float)hovered_cell->x, (float)hovered_cell->y);
|
||||
// Create Vector object for cell position - must fetch finalized type from module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (vector_type) {
|
||||
PyObject* cell_pos = PyObject_CallFunction(vector_type, "ff", (float)hovered_cell->x, (float)hovered_cell->y);
|
||||
Py_DECREF(vector_type);
|
||||
if (cell_pos) {
|
||||
PyObject* args = Py_BuildValue("(O)", cell_pos);
|
||||
Py_DECREF(cell_pos);
|
||||
|
|
@ -2264,11 +2275,15 @@ void UIGrid::updateCellHover(sf::Vector2f mousepos) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fire enter callback for new cell
|
||||
if (new_cell.has_value() && on_cell_enter_callable) {
|
||||
// Create Vector object for cell position
|
||||
PyObject* cell_pos = PyObject_CallFunction((PyObject*)&mcrfpydef::PyVectorType, "ff", (float)new_cell->x, (float)new_cell->y);
|
||||
// Create Vector object for cell position - must fetch finalized type from module
|
||||
PyObject* vector_type = PyObject_GetAttrString(McRFPy_API::mcrf_module, "Vector");
|
||||
if (vector_type) {
|
||||
PyObject* cell_pos = PyObject_CallFunction(vector_type, "ff", (float)new_cell->x, (float)new_cell->y);
|
||||
Py_DECREF(vector_type);
|
||||
if (cell_pos) {
|
||||
PyObject* args = Py_BuildValue("(O)", cell_pos);
|
||||
Py_DECREF(cell_pos);
|
||||
|
|
@ -2283,6 +2298,7 @@ void UIGrid::updateCellHover(sf::Vector2f mousepos) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hovered_cell = new_cell;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue