Fix Sprite texture setter 'error return without exception set'
Implemented the missing UISprite::set_texture method to properly: - Validate the input is a Texture instance - Update the sprite's texture using setTexture() - Return appropriate error messages for invalid inputs The setter now works correctly and no longer returns -1 without setting an exception.
This commit is contained in:
parent
6dd1cec600
commit
4715356b5e
2 changed files with 90 additions and 1 deletions
|
|
@ -162,7 +162,23 @@ PyObject* UISprite::get_texture(PyUISpriteObject* self, void* closure)
|
|||
|
||||
int UISprite::set_texture(PyUISpriteObject* self, PyObject* value, void* closure)
|
||||
{
|
||||
return -1;
|
||||
// Check if value is a Texture instance
|
||||
if (!PyObject_IsInstance(value, PyObject_GetAttrString(McRFPy_API::mcrf_module, "Texture"))) {
|
||||
PyErr_SetString(PyExc_TypeError, "texture must be a mcrfpy.Texture instance");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get the texture from the Python object
|
||||
auto pytexture = (PyTextureObject*)value;
|
||||
if (!pytexture->data) {
|
||||
PyErr_SetString(PyExc_ValueError, "Invalid texture object");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Update the sprite's texture
|
||||
self->data->setTexture(pytexture->data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyGetSetDef UISprite::getsetters[] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue