[BUG]: Function with Param of type `const Eigen::VectorXd&` causes "windows fatal exception: access violation" on Windows
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
调研方向
从可复现的 pybind11 模块开始,在列出的 Windows、Visual Studio、Python 和 pybind11 版本下,比较 set_data 参数采用 const Eigen::VectorXd& 与 Eigen::Ref 时的情况。通过包含的 pybind11/eigen.h 路径追踪转换行为,并与 stable branch 进行比较。完成标准是确定访问冲突的原因,并在所报告的所有环境中定义或应用经过验证的修复。
由索引模型根据 Issue 内容生成。
描述
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
v2.10.4
Problem description
When calling function with parameter const Eigen::VectorXd&, it fails with "windows fatal exception: access violation" on Windows, compiled with VS2022, Python 3.12, and Pybind v2.10.4.
However, the example works well with Python 3.10 + VS2019 + Pybind v2.10.4.
Besides, it also works well in Python 3.12 + VS2022 + Pybind current stable branch.
I know from the Documentation that it recommend using Eigen::Ref for reference. Using Eigen::Ref, Python 3.12 + VS2022 + Pybind v2.10.4 also works.
That said, using either Pybind current stable branch or Eigen::Ref can make it work.
I have been struggling on this issue for a while.
I want to understand how things go wrong:
- Why
Eigen::Refworks, butconst Eigen::VectorXd¬? - Why Pybind current stable branch works?
Reproducible example code
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/functional.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include <vector>
#include <Eigen/Eigen>
namespace py = pybind11;
class ArrayDynamic {
using Vector =Eigen::VectorXd;
private:
Vector data_;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
ArrayDynamic() = default;
virtual ~ArrayDynamic() = default;
explicit ArrayDynamic(size_t dim) { data_.resize(dim); }
auto data() const -> const Vector& { return data_; }
auto data() -> Vector& { return data_; }
};
PYBIND11_MODULE(promote, m)
{
auto math = m.def_submodule("math");
py::class_<ArrayDynamic>(math, "ArrayDynamic")
.def(py::init<size_t>(), "Create an array of given size.", py::arg("dim"))
.def("data", py::overload_cast<>(&ArrayDynamic::data), py::return_value_policy::reference_internal, "internal")
.def( "set_data",
[](ArrayDynamic& array,
const Eigen::VectorXd& data)
{
array.data() = data;
},
"Set data.");
}
For a full example, see https://github.com/huweiATgithub/pybind_fail_example
### Is this a regression? Put the last known working version here if it is.
Not a regression
- 主要语言
- C++
- 星标
- 18k
- 派生
- 2.3k
- 平均合并
- 5 天 7 小时
- 30 天内合并 PR
- 53
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pybind/pybind11 的其他 Issue
-
triage
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 4 天内回复
-
triage
难度 1/5 1 小时以内 新手友好度 62/100
pybind/pybind11#5604 · 1 条评论 ·
维护者通常 4 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 4 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 60/100
维护者通常 4 天内回复
-
array_t::at() returns a misaligned reference when the stride is not a multiple of alignof(T)可能已有人在做 @henryiii 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 35/100
维护者通常 4 天内回复
相似的 Issue
-
[Bug] Windows Ghidra provider rejects a PATH-only JDK: bare `java.exe` probe fails with Win32 87未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
type:bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
tenstorrent/tt-umd#4084 ·
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
ToffelsKater/X4_VR#34 ·
-
difficulty:easy prio:low refactor
难度 2/5 1-3 小时 新手友好度 72/100
NatronGitHub/openfx-supportext#220 ·
维护者通常 1 天内回复