You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, in Visual Studio (MSVC), runtime assertions prevent accessing any index out of range, including the "one-past-the-end" pointer returned by end(). This leads to a runtime exception when trying to access this position.
Problem
The MSVC runtime checks throw an exception due to the pointer being out of bounds, even though the pointer is intentionally pointing to the "past-the-end" element (the valid position after the last element in the container). The runtime enforcement causes issues with valid code and is not necessary for such access.
Workaround
There is a workaround to disable the runtime assertions by using the following preprocessor directive:
#define_CONTAINER_DEBUG_LEVEL0// Disable the debug level for the container
However, this is not a desirable solution, as it bypasses helpful runtime checks and reduces the safety of the code.
Suggestion
It would be better to adjust the implementation to avoid triggering MSVC's runtime assertions. One possible solution is to use std::vector::data() and compute the "one-past-the-end" pointer without triggering any bounds checking:
T* end() { return m_data.data() + size(); }
This approach should be safe and avoid the MSVC runtime assertions while maintaining the correctness of the code.
The text was updated successfully, but these errors were encountered:
Description
In the implementation of
glsl::vector
, the following methods are used to return a pointer to the element after the last element:glsl-parser/util.h
Lines 31 to 33 in 8fd08ed
However, in Visual Studio (MSVC), runtime assertions prevent accessing any index out of range, including the "one-past-the-end" pointer returned by
end()
. This leads to a runtime exception when trying to access this position.Problem
The MSVC runtime checks throw an exception due to the pointer being out of bounds, even though the pointer is intentionally pointing to the "past-the-end" element (the valid position after the last element in the container). The runtime enforcement causes issues with valid code and is not necessary for such access.
Workaround
There is a workaround to disable the runtime assertions by using the following preprocessor directive:
However, this is not a desirable solution, as it bypasses helpful runtime checks and reduces the safety of the code.
Suggestion
It would be better to adjust the implementation to avoid triggering MSVC's runtime assertions. One possible solution is to use std::vector::data() and compute the "one-past-the-end" pointer without triggering any bounds checking:
This approach should be safe and avoid the MSVC runtime assertions while maintaining the correctness of the code.
The text was updated successfully, but these errors were encountered: