-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vulkan: Crash when baking lightmaps with LightmapGI if the resulting image is too large (due to CowData using 32-bit ints) #54679
Comments
The atlas in this scene is 16384x16384 which means it has exactly Since The check in Line 1987 in 82a9995
On one hand we should make sure all the size limits are correctly checked, both on |
I've tried to make sure diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h
index e79ca037db..770496d285 100644
--- a/core/templates/cowdata.h
+++ b/core/templates/cowdata.h
@@ -135,7 +135,7 @@ public:
return _get_data();
}
- _FORCE_INLINE_ int size() const {
+ _FORCE_INLINE_ uint32_t size() const {
uint32_t *size = (uint32_t *)_get_size();
if (size) {
return *size;
@@ -147,41 +147,41 @@ public:
_FORCE_INLINE_ void clear() { resize(0); }
_FORCE_INLINE_ bool is_empty() const { return _ptr == nullptr; }
- _FORCE_INLINE_ void set(int p_index, const T &p_elem) {
+ _FORCE_INLINE_ void set(uint32_t p_index, const T &p_elem) {
ERR_FAIL_INDEX(p_index, size());
_copy_on_write();
_get_data()[p_index] = p_elem;
}
- _FORCE_INLINE_ T &get_m(int p_index) {
+ _FORCE_INLINE_ T &get_m(uint32_t p_index) {
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
return _get_data()[p_index];
}
- _FORCE_INLINE_ const T &get(int p_index) const {
+ _FORCE_INLINE_ const T &get(uint32_t p_index) const {
CRASH_BAD_INDEX(p_index, size());
return _get_data()[p_index];
}
- Error resize(int p_size);
+ Error resize(uint32_t p_size);
- _FORCE_INLINE_ void remove_at(int p_index) {
+ _FORCE_INLINE_ void remove_at(uint32_t p_index) {
ERR_FAIL_INDEX(p_index, size());
T *p = ptrw();
- int len = size();
- for (int i = p_index; i < len - 1; i++) {
+ uint32_t len = size();
+ for (uint32_t i = p_index; i < len - 1; i++) {
p[i] = p[i + 1];
}
resize(len - 1);
}
- Error insert(int p_pos, const T &p_val) {
+ Error insert(uint32_t p_pos, const T &p_val) {
ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER);
resize(size() + 1);
- for (int i = (size() - 1); i > p_pos; i--) {
+ for (uint32_t i = (size() - 1); i > p_pos; i--) {
set(i, get(i - 1));
}
set(p_pos, p_val);
@@ -189,7 +189,7 @@ public:
return OK;
}
- int find(const T &p_val, int p_from = 0) const;
+ uint32_t find(const T &p_val, uint32_t p_from = 0) const;
_FORCE_INLINE_ CowData() {}
_FORCE_INLINE_ ~CowData();
@@ -262,10 +262,10 @@ uint32_t CowData<T>::_copy_on_write() {
}
template <class T>
-Error CowData<T>::resize(int p_size) {
+Error CowData<T>::resize(uint32_t p_size) {
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
- int current_size = size();
+ uint32_t current_size = size();
if (p_size == current_size) {
return OK;
@@ -310,7 +310,7 @@ Error CowData<T>::resize(int p_size) {
if (!__has_trivial_constructor(T)) {
T *elems = _get_data();
- for (int i = *_get_size(); i < p_size; i++) {
+ for (uint32_t i = *_get_size(); i < p_size; i++) {
memnew_placement(&elems[i], T);
}
}
@@ -341,14 +341,14 @@ Error CowData<T>::resize(int p_size) {
}
template <class T>
-int CowData<T>::find(const T &p_val, int p_from) const {
- int ret = -1;
+uint32_t CowData<T>::find(const T &p_val, uint32_t p_from) const {
+ uint32_t ret = -1;
if (p_from < 0 || size() == 0) {
return ret;
}
- for (int i = p_from; i < size(); i++) {
+ for (uint32_t i = p_from; i < size(); i++) {
if (get(i) == p_val) {
ret = i;
break;
|
It seems to be crashing (at least on macOS) at Line 1960 in 9c6c71b
size is int and is overflown, value at the moment of crash is -2147483648 .
|
Not sure if this is the same crash, but I'm trying to light something imported from QODOT.
buffer_size = 2224175008 (slightly larger than 2 gigs?) I tried setting the max lightmap size to 2048, the smallest it would allow, but I still get the crash. Edit: Changing the texel unwrap size setting in Qodot from 1 to 16 seems to have fixed it. |
Godot version
4.0.dev (4651b2a)
System information
Fedora 34, GeForce GTX 1080 (NVIDIA 470.74)
Issue description
The editor crashes when baking lightmaps with LightmapGI in a specific scene (see the MRP included).
Backtrace:
Steps to reproduce
Minimal reproduction project
global_illumination.zip
The text was updated successfully, but these errors were encountered: