Avoid overflowing the stack when allocating memory for polytope in EPA.

PiperOrigin-RevId: 688641864
Change-Id: I3eef7e821ffbfa8d97a946ecf86d098cb4f0c233
This commit is contained in:
Kyle Bayes
2024-10-22 12:10:29 -07:00
committed by Copybara-Service
parent 4a3f77dd1f
commit 0c97dcf1fd
3 changed files with 35 additions and 7 deletions
+14
View File
@@ -1715,6 +1715,20 @@ void mj__freeStack(mjData* d)
// returns the number of bytes available on the stack
size_t mj_stackBytesAvailable(mjData* d) {
if (!d->threadpool) {
mjStackInfo stack_info = get_stack_info_from_data(d);
return stack_info.top - stack_info.limit;
} else {
size_t thread_id = mju_threadPoolCurrentWorkerId((mjThreadPool*)d->threadpool);
mjStackInfo* stack_info = mju_getStackInfoForThread(d, thread_id);
return stack_info->top - stack_info->limit;
}
}
// allocate bytes on the stack
void* mj_stackAllocByte(mjData* d, size_t bytes, size_t alignment) {
return stackalloc(d, bytes, alignment);