Fix Entity3D.viewport returning None, closes #244

The root cause was PyViewport3DType being declared `static` in
Viewport3D.h, creating per-translation-unit copies. Entity3D.cpp's
copy was never passed through PyType_Ready, causing segfaults when
tp_alloc was called.

Changed `static` to `inline` (matching PyEntity3DType and
PyModel3DType patterns), and implemented get_viewport using the
standard type->tp_alloc pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-02-07 20:15:38 -05:00
commit 2062e4e4ad
3 changed files with 193 additions and 12 deletions

View file

@ -89,8 +89,9 @@ public:
/// Convert screen coordinates to world position via ray casting
/// @param screenX X position relative to viewport
/// @param screenY Y position relative to viewport
/// @return World position on Y=0 plane, or (-1,-1,-1) if no intersection
vec3 screenToWorld(float screenX, float screenY);
/// @param yPlane Y value of the horizontal plane to intersect (default: 0)
/// @return World position on the given Y plane, or (-1,-1,-1) if no intersection
vec3 screenToWorld(float screenX, float screenY, float yPlane = 0.0f);
/// Position camera to follow an entity
/// @param entity Entity to follow
@ -402,7 +403,7 @@ extern PyMethodDef Viewport3D_methods[];
namespace mcrfpydef {
static PyTypeObject PyViewport3DType = {
inline PyTypeObject PyViewport3DType = {
.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0},
.tp_name = "mcrfpy.Viewport3D",
.tp_basicsize = sizeof(PyViewport3DObject),