Remove usage of size_t types in mjModel, use mjtSize (uint64_t) instead to improve portabilty of MJB files to WASM.
PiperOrigin-RevId: 789321991 Change-Id: Ic25fab876c347fc75f5ca24cad09e8fd972f035f
This commit is contained in:
committed by
Copybara-Service
parent
4c288c19ac
commit
23fa7c00d5
@@ -91,6 +91,18 @@ Byte type used to represent boolean variables.
|
|||||||
typedef unsigned char mjtByte;
|
typedef unsigned char mjtByte;
|
||||||
|
|
||||||
|
|
||||||
|
.. _mjtSize:
|
||||||
|
|
||||||
|
mjtSize
|
||||||
|
^^^^^^^
|
||||||
|
|
||||||
|
Size type used to represent buffer sizes.
|
||||||
|
|
||||||
|
.. code-block:: C
|
||||||
|
|
||||||
|
typedef uint64_t mjtSize;
|
||||||
|
|
||||||
|
|
||||||
.. _tyEnums:
|
.. _tyEnums:
|
||||||
|
|
||||||
Enum types
|
Enum types
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ struct mjSolverStat_ { // per-iteration solver statistics
|
|||||||
typedef struct mjSolverStat_ mjSolverStat;
|
typedef struct mjSolverStat_ mjSolverStat;
|
||||||
struct mjData_ {
|
struct mjData_ {
|
||||||
// constant sizes
|
// constant sizes
|
||||||
size_t narena; // size of the arena in bytes (inclusive of the stack)
|
mjtSize narena; // size of the arena in bytes (inclusive of the stack)
|
||||||
size_t nbuffer; // size of main buffer in bytes
|
mjtSize nbuffer; // size of main buffer in bytes
|
||||||
int nplugin; // number of plugin instances
|
int nplugin; // number of plugin instances
|
||||||
|
|
||||||
// stack pointer
|
// stack pointer
|
||||||
@@ -146,9 +146,9 @@ struct mjData_ {
|
|||||||
size_t parena; // first available byte in arena
|
size_t parena; // first available byte in arena
|
||||||
|
|
||||||
// memory utilization statistics
|
// memory utilization statistics
|
||||||
size_t maxuse_stack; // maximum stack allocation in bytes
|
mjtSize maxuse_stack; // maximum stack allocation in bytes
|
||||||
size_t maxuse_threadstack[mjMAXTHREAD]; // maximum stack allocation per thread in bytes
|
mjtSize maxuse_threadstack[mjMAXTHREAD]; // maximum stack allocation per thread in bytes
|
||||||
size_t maxuse_arena; // maximum arena allocation in bytes
|
mjtSize maxuse_arena; // maximum arena allocation in bytes
|
||||||
int maxuse_con; // maximum number of contacts
|
int maxuse_con; // maximum number of contacts
|
||||||
int maxuse_efc; // maximum number of scalar constraints
|
int maxuse_efc; // maximum number of scalar constraints
|
||||||
|
|
||||||
@@ -1056,8 +1056,8 @@ struct mjModel_ {
|
|||||||
int nsensordata; // number of mjtNums in sensor data vector
|
int nsensordata; // number of mjtNums in sensor data vector
|
||||||
int npluginstate; // number of mjtNums in plugin state vector
|
int npluginstate; // number of mjtNums in plugin state vector
|
||||||
|
|
||||||
size_t narena; // number of bytes in the mjData arena (inclusive of stack)
|
mjtSize narena; // number of bytes in the mjData arena (inclusive of stack)
|
||||||
size_t nbuffer; // number of bytes in buffer
|
mjtSize nbuffer; // number of bytes in buffer
|
||||||
|
|
||||||
// ------------------------------- options and statistics
|
// ------------------------------- options and statistics
|
||||||
|
|
||||||
@@ -1866,7 +1866,7 @@ typedef struct mjSpec_ { // model specification
|
|||||||
mjStatistic stat; // statistics override (if defined)
|
mjStatistic stat; // statistics override (if defined)
|
||||||
|
|
||||||
// sizes
|
// sizes
|
||||||
size_t memory; // number of bytes in arena+stack memory
|
mjtSize memory; // number of bytes in arena+stack memory
|
||||||
int nemax; // max number of equality constraints
|
int nemax; // max number of equality constraints
|
||||||
int nuserdata; // number of mjtNums in userdata
|
int nuserdata; // number of mjtNums in userdata
|
||||||
int nuser_body; // number of mjtNums in body_user
|
int nuser_body; // number of mjtNums in body_user
|
||||||
@@ -1880,7 +1880,7 @@ typedef struct mjSpec_ { // model specification
|
|||||||
int nkey; // number of keyframes
|
int nkey; // number of keyframes
|
||||||
int njmax; // (deprecated) max number of constraints
|
int njmax; // (deprecated) max number of constraints
|
||||||
int nconmax; // (deprecated) max number of detected contacts
|
int nconmax; // (deprecated) max number of detected contacts
|
||||||
size_t nstack; // (deprecated) number of mjtNums in mjData stack
|
mjtSize nstack; // (deprecated) number of mjtNums in mjData stack
|
||||||
|
|
||||||
// global data
|
// global data
|
||||||
mjString* comment; // comment at top of XML
|
mjString* comment; // comment at top of XML
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ typedef struct mjSolverStat_ mjSolverStat;
|
|||||||
|
|
||||||
struct mjData_ {
|
struct mjData_ {
|
||||||
// constant sizes
|
// constant sizes
|
||||||
size_t narena; // size of the arena in bytes (inclusive of the stack)
|
mjtSize narena; // size of the arena in bytes (inclusive of the stack)
|
||||||
size_t nbuffer; // size of main buffer in bytes
|
mjtSize nbuffer; // size of main buffer in bytes
|
||||||
int nplugin; // number of plugin instances
|
int nplugin; // number of plugin instances
|
||||||
|
|
||||||
// stack pointer
|
// stack pointer
|
||||||
@@ -174,9 +174,9 @@ struct mjData_ {
|
|||||||
size_t parena; // first available byte in arena
|
size_t parena; // first available byte in arena
|
||||||
|
|
||||||
// memory utilization statistics
|
// memory utilization statistics
|
||||||
size_t maxuse_stack; // maximum stack allocation in bytes
|
mjtSize maxuse_stack; // maximum stack allocation in bytes
|
||||||
size_t maxuse_threadstack[mjMAXTHREAD]; // maximum stack allocation per thread in bytes
|
mjtSize maxuse_threadstack[mjMAXTHREAD]; // maximum stack allocation per thread in bytes
|
||||||
size_t maxuse_arena; // maximum arena allocation in bytes
|
mjtSize maxuse_arena; // maximum arena allocation in bytes
|
||||||
int maxuse_con; // maximum number of contacts
|
int maxuse_con; // maximum number of contacts
|
||||||
int maxuse_efc; // maximum number of scalar constraints
|
int maxuse_efc; // maximum number of scalar constraints
|
||||||
|
|
||||||
|
|||||||
@@ -731,8 +731,8 @@ struct mjModel_ {
|
|||||||
int nsensordata; // number of mjtNums in sensor data vector
|
int nsensordata; // number of mjtNums in sensor data vector
|
||||||
int npluginstate; // number of mjtNums in plugin state vector
|
int npluginstate; // number of mjtNums in plugin state vector
|
||||||
|
|
||||||
size_t narena; // number of bytes in the mjData arena (inclusive of stack)
|
mjtSize narena; // number of bytes in the mjData arena (inclusive of stack)
|
||||||
size_t nbuffer; // number of bytes in buffer
|
mjtSize nbuffer; // number of bytes in buffer
|
||||||
|
|
||||||
// ------------------------------- options and statistics
|
// ------------------------------- options and statistics
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ typedef struct mjSpec_ { // model specification
|
|||||||
mjStatistic stat; // statistics override (if defined)
|
mjStatistic stat; // statistics override (if defined)
|
||||||
|
|
||||||
// sizes
|
// sizes
|
||||||
size_t memory; // number of bytes in arena+stack memory
|
mjtSize memory; // number of bytes in arena+stack memory
|
||||||
int nemax; // max number of equality constraints
|
int nemax; // max number of equality constraints
|
||||||
int nuserdata; // number of mjtNums in userdata
|
int nuserdata; // number of mjtNums in userdata
|
||||||
int nuser_body; // number of mjtNums in body_user
|
int nuser_body; // number of mjtNums in body_user
|
||||||
@@ -184,7 +184,7 @@ typedef struct mjSpec_ { // model specification
|
|||||||
int nkey; // number of keyframes
|
int nkey; // number of keyframes
|
||||||
int njmax; // (deprecated) max number of constraints
|
int njmax; // (deprecated) max number of constraints
|
||||||
int nconmax; // (deprecated) max number of detected contacts
|
int nconmax; // (deprecated) max number of detected contacts
|
||||||
size_t nstack; // (deprecated) number of mjtNums in mjData stack
|
mjtSize nstack; // (deprecated) number of mjtNums in mjData stack
|
||||||
|
|
||||||
// global data
|
// global data
|
||||||
mjString* comment; // comment at top of XML
|
mjString* comment; // comment at top of XML
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
#ifndef MUJOCO_INCLUDE_MJTNUM_H_
|
#ifndef MUJOCO_INCLUDE_MJTNUM_H_
|
||||||
#define MUJOCO_INCLUDE_MJTNUM_H_
|
#define MUJOCO_INCLUDE_MJTNUM_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
//---------------------------------- floating-point definition -------------------------------------
|
//---------------------------------- floating-point definition -------------------------------------
|
||||||
|
|
||||||
// floating point data type and minval
|
// floating point data type and minval
|
||||||
@@ -34,4 +36,10 @@ typedef unsigned char mjtByte; // used for true/false
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------- size definition -------------------------------------------
|
||||||
|
|
||||||
|
typedef uint64_t mjtSize; // used for buffer sizes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // MUJOCO_INCLUDE_MJTNUM_H_
|
#endif // MUJOCO_INCLUDE_MJTNUM_H_
|
||||||
|
|||||||
@@ -1255,12 +1255,12 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
|||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='narena',
|
name='narena',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='number of bytes in the mjData arena (inclusive of stack)',
|
doc='number of bytes in the mjData arena (inclusive of stack)',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='nbuffer',
|
name='nbuffer',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='number of bytes in buffer',
|
doc='number of bytes in buffer',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
@@ -4866,12 +4866,12 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
|||||||
fields=(
|
fields=(
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='narena',
|
name='narena',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='size of the arena in bytes (inclusive of the stack)',
|
doc='size of the arena in bytes (inclusive of the stack)',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='nbuffer',
|
name='nbuffer',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='size of main buffer in bytes',
|
doc='size of main buffer in bytes',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
@@ -4896,20 +4896,20 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
|||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='maxuse_stack',
|
name='maxuse_stack',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='maximum stack allocation in bytes',
|
doc='maximum stack allocation in bytes',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='maxuse_threadstack',
|
name='maxuse_threadstack',
|
||||||
type=ArrayType(
|
type=ArrayType(
|
||||||
inner_type=ValueType(name='size_t'),
|
inner_type=ValueType(name='mjtSize'),
|
||||||
extents=(128,),
|
extents=(128,),
|
||||||
),
|
),
|
||||||
doc='maximum stack allocation per thread in bytes',
|
doc='maximum stack allocation per thread in bytes',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='maxuse_arena',
|
name='maxuse_arena',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='maximum arena allocation in bytes',
|
doc='maximum arena allocation in bytes',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
@@ -8043,7 +8043,7 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
|||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='memory',
|
name='memory',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='number of bytes in arena+stack memory',
|
doc='number of bytes in arena+stack memory',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
@@ -8113,7 +8113,7 @@ STRUCTS: Mapping[str, StructDecl] = dict([
|
|||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
name='nstack',
|
name='nstack',
|
||||||
type=ValueType(name='size_t'),
|
type=ValueType(name='mjtSize'),
|
||||||
doc='(deprecated) number of mjtNums in mjData stack',
|
doc='(deprecated) number of mjtNums in mjData stack',
|
||||||
),
|
),
|
||||||
StructFieldDecl(
|
StructFieldDecl(
|
||||||
|
|||||||
+35
-24
@@ -12,9 +12,9 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
#include "engine/engine_io.h"
|
#include "engine/engine_io.h"
|
||||||
|
|
||||||
|
#include <inttypes.h> // NOLINT required for PRIu64
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <mujoco/mjmodel.h>
|
|
||||||
#include <mujoco/mjmacro.h>
|
#include <mujoco/mjmacro.h>
|
||||||
|
#include <mujoco/mjmodel.h>
|
||||||
#include <mujoco/mjplugin.h>
|
#include <mujoco/mjplugin.h>
|
||||||
#include <mujoco/mjsan.h> // IWYU pragma: keep
|
#include <mujoco/mjsan.h> // IWYU pragma: keep
|
||||||
#include <mujoco/mjxmacro.h>
|
#include <mujoco/mjxmacro.h>
|
||||||
@@ -320,11 +320,11 @@ static int getnint(void) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// count size_t members in mjModel
|
// count buffer members in mjModel (mjtSize)
|
||||||
static int getnsize(void) {
|
static int getnbuffer(void) {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
#define X(name) cnt += _Generic(MJMODEL_MEMBER(name), size_t: 1, default: 0);
|
#define X(name) cnt += _Generic(MJMODEL_MEMBER(name), mjtSize: 1, default: 0);
|
||||||
MJMODEL_INTS
|
MJMODEL_INTS
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
@@ -414,7 +414,10 @@ static void mj_setPtrModel(mjModel* m) {
|
|||||||
// check size
|
// check size
|
||||||
ptrdiff_t sz = ptr - (char*)m->buffer;
|
ptrdiff_t sz = ptr - (char*)m->buffer;
|
||||||
if (m->nbuffer != sz) {
|
if (m->nbuffer != sz) {
|
||||||
mjERROR("mjModel buffer size mismatch, expected size: %zd, actual size: %zu", m->nbuffer, sz);
|
mjERROR(
|
||||||
|
"mjModel buffer size mismatch, "
|
||||||
|
"expected size: %" PRIu64 ", actual size: %td",
|
||||||
|
m->nbuffer, sz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,7 +428,7 @@ static void mj_setPtrModel(mjModel* m) {
|
|||||||
// performs the following operations:
|
// performs the following operations:
|
||||||
// *nbuffer += SKIP(*offset) + type_size*nr*nc;
|
// *nbuffer += SKIP(*offset) + type_size*nr*nc;
|
||||||
// *offset += SKIP(*offset) + type_size*nr*nc;
|
// *offset += SKIP(*offset) + type_size*nr*nc;
|
||||||
static int safeAddToBufferSize(intptr_t* offset, size_t* nbuffer,
|
static int safeAddToBufferSize(intptr_t* offset, mjtSize* nbuffer,
|
||||||
size_t type_size, int nr, int nc) {
|
size_t type_size, int nr, int nc) {
|
||||||
if (type_size < 0 || nr < 0 || nc < 0) {
|
if (type_size < 0 || nr < 0 || nc < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -724,7 +727,7 @@ void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buff
|
|||||||
int ptrbuf = 0;
|
int ptrbuf = 0;
|
||||||
|
|
||||||
// standard header
|
// standard header
|
||||||
int header[NHEADER] = {ID, sizeof(mjtNum), getnint(), getnsize(), getnptr()};
|
int header[NHEADER] = {ID, sizeof(mjtNum), getnint(), getnbuffer(), getnptr()};
|
||||||
|
|
||||||
// open file for writing if no buffer
|
// open file for writing if no buffer
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
@@ -752,7 +755,7 @@ void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buff
|
|||||||
#undef X
|
#undef X
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bufwrite(header, sizeof(int)*sizeof(header) / sizeof(int), buffer_sz, buffer, &ptrbuf);
|
bufwrite(header, sizeof(header), buffer_sz, buffer, &ptrbuf);
|
||||||
#define X(name) bufwrite(&m->name, sizeof(m->name), buffer_sz, buffer, &ptrbuf);
|
#define X(name) bufwrite(&m->name, sizeof(m->name), buffer_sz, buffer, &ptrbuf);
|
||||||
MJMODEL_INTS
|
MJMODEL_INTS
|
||||||
#undef X
|
#undef X
|
||||||
@@ -776,10 +779,6 @@ void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buff
|
|||||||
|
|
||||||
// load binary MJB model
|
// load binary MJB model
|
||||||
mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
|
mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
|
||||||
int header[NHEADER] = {0};
|
|
||||||
int expected_header[NHEADER] = {ID, sizeof(mjtNum), getnint(), getnsize(), getnptr()};
|
|
||||||
int ints[256];
|
|
||||||
size_t sizes[8];
|
|
||||||
int ptrbuf = 0;
|
int ptrbuf = 0;
|
||||||
mjModel *m = 0;
|
mjModel *m = 0;
|
||||||
|
|
||||||
@@ -788,9 +787,11 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int header[NHEADER] = {0};
|
||||||
bufread(header, NHEADER*sizeof(int), buffer_sz, buffer, &ptrbuf);
|
bufread(header, NHEADER*sizeof(int), buffer_sz, buffer, &ptrbuf);
|
||||||
|
|
||||||
// check header
|
// check header
|
||||||
|
int expected_header[NHEADER] = {ID, sizeof(mjtNum), getnint(), getnbuffer(), getnptr()};
|
||||||
for (int i=0; i < NHEADER; i++) {
|
for (int i=0; i < NHEADER; i++) {
|
||||||
if (header[i] != expected_header[i]) {
|
if (header[i] != expected_header[i]) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
@@ -817,15 +818,16 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read mjModel structure: info only
|
if (ptrbuf + sizeof(int)*getnint() + sizeof(mjtSize)*getnbuffer() > buffer_sz) {
|
||||||
if (ptrbuf + sizeof(int)*getnint() + sizeof(size_t)*getnsize() > buffer_sz) {
|
|
||||||
mju_warning("Truncated model file - ran out of data while reading sizes");
|
mju_warning("Truncated model file - ran out of data while reading sizes");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bufread(ints, sizeof(int)*getnint(), buffer_sz, buffer, &ptrbuf);
|
|
||||||
bufread(sizes, sizeof(size_t)*getnsize(), buffer_sz, buffer, &ptrbuf);
|
|
||||||
|
|
||||||
// allocate new mjModel, check sizes
|
// read mjModel construction fields
|
||||||
|
int ints[256];
|
||||||
|
bufread(ints, sizeof(int)*getnint(), buffer_sz, buffer, &ptrbuf);
|
||||||
|
|
||||||
|
// allocate new mjModel
|
||||||
mj_makeModel(&m,
|
mj_makeModel(&m,
|
||||||
ints[0], ints[1], ints[2], ints[3], ints[4], ints[5], ints[6],
|
ints[0], ints[1], ints[2], ints[3], ints[4], ints[5], ints[6],
|
||||||
ints[7], ints[8], ints[9], ints[10], ints[11], ints[12], ints[13],
|
ints[7], ints[8], ints[9], ints[10], ints[11], ints[12], ints[13],
|
||||||
@@ -837,8 +839,14 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
|
|||||||
ints[49], ints[50], ints[51], ints[52], ints[53], ints[54], ints[55],
|
ints[49], ints[50], ints[51], ints[52], ints[53], ints[54], ints[55],
|
||||||
ints[56], ints[57], ints[58], ints[59], ints[60], ints[61], ints[62],
|
ints[56], ints[57], ints[58], ints[59], ints[60], ints[61], ints[62],
|
||||||
ints[63], ints[64], ints[65], ints[66], ints[67], ints[68], ints[69]);
|
ints[63], ints[64], ints[65], ints[66], ints[67], ints[68], ints[69]);
|
||||||
if (!m || m->nbuffer != sizes[getnsize()-1]) {
|
|
||||||
mju_warning("Corrupted model, wrong size parameters");
|
// read mjModel mjtSize fields
|
||||||
|
mjtSize sizes[8];
|
||||||
|
bufread(sizes, sizeof(mjtSize)*getnbuffer(), buffer_sz, buffer, &ptrbuf);
|
||||||
|
|
||||||
|
// check mjtSize fields
|
||||||
|
if (!m || m->nbuffer != sizes[getnbuffer()-1]) {
|
||||||
|
mju_warning("Corrupted model, wrong nbuffer field");
|
||||||
mj_deleteModel(m);
|
mj_deleteModel(m);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -848,7 +856,7 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
|
|||||||
int int_idx = 0;
|
int int_idx = 0;
|
||||||
int size_idx = 0;
|
int size_idx = 0;
|
||||||
#define X(name) \
|
#define X(name) \
|
||||||
m->name = _Generic(m->name, size_t: sizes[size_idx++], default: ints[int_idx++]);
|
m->name = _Generic(m->name, mjtSize: sizes[size_idx++], default: ints[int_idx++]);
|
||||||
MJMODEL_INTS
|
MJMODEL_INTS
|
||||||
#undef X
|
#undef X
|
||||||
}
|
}
|
||||||
@@ -908,7 +916,7 @@ void mj_deleteModel(mjModel* m) {
|
|||||||
int mj_sizeModel(const mjModel* m) {
|
int mj_sizeModel(const mjModel* m) {
|
||||||
int size = (
|
int size = (
|
||||||
sizeof(int)*(NHEADER+getnint())
|
sizeof(int)*(NHEADER+getnint())
|
||||||
+ sizeof(size_t)*getnsize()
|
+ sizeof(mjtSize)*getnbuffer()
|
||||||
+ sizeof(mjOption)
|
+ sizeof(mjOption)
|
||||||
+ sizeof(mjVisual)
|
+ sizeof(mjVisual)
|
||||||
+ sizeof(mjStatistic));
|
+ sizeof(mjStatistic));
|
||||||
@@ -1285,7 +1293,10 @@ static void mj_setPtrData(const mjModel* m, mjData* d) {
|
|||||||
// check size
|
// check size
|
||||||
ptrdiff_t sz = ptr - (char*)d->buffer;
|
ptrdiff_t sz = ptr - (char*)d->buffer;
|
||||||
if (d->nbuffer != sz) {
|
if (d->nbuffer != sz) {
|
||||||
mjERROR("mjData buffer size mismatch, expected size: %zd, actual size: %zu", d->nbuffer, sz);
|
mjERROR(
|
||||||
|
"mjData buffer size mismatch, "
|
||||||
|
"expected size: %" PRIu64 ", actual size: %td",
|
||||||
|
d->nbuffer, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
// zero-initialize arena pointers
|
// zero-initialize arena pointers
|
||||||
@@ -1928,7 +1939,7 @@ static void _resetData(const mjModel* m, mjData* d, unsigned char debug_value) {
|
|||||||
|
|
||||||
// clear memory utilization stats
|
// clear memory utilization stats
|
||||||
d->maxuse_stack = 0;
|
d->maxuse_stack = 0;
|
||||||
mju_zeroSizeT(d->maxuse_threadstack, mjMAXTHREAD);
|
mju_zeroSize(d->maxuse_threadstack, mjMAXTHREAD);
|
||||||
d->maxuse_arena = 0;
|
d->maxuse_arena = 0;
|
||||||
d->maxuse_con = 0;
|
d->maxuse_con = 0;
|
||||||
d->maxuse_efc = 0;
|
d->maxuse_efc = 0;
|
||||||
|
|||||||
@@ -1367,7 +1367,12 @@ void mju_zeroInt(int* res, int n) {
|
|||||||
memset(res, 0, n*sizeof(int));
|
memset(res, 0, n*sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set mjtSize vector to 0
|
||||||
|
void mju_zeroSize(mjtSize* res, size_t n) {
|
||||||
|
memset(res, 0, n*sizeof(mjtSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
// set size_t vector to 0
|
||||||
void mju_zeroSizeT(size_t* res, size_t n) {
|
void mju_zeroSizeT(size_t* res, size_t n) {
|
||||||
memset(res, 0, n*sizeof(size_t));
|
memset(res, 0, n*sizeof(size_t));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,6 +139,9 @@ MJAPI int mju_isZero(mjtNum* vec, int n);
|
|||||||
// set integer vector to 0
|
// set integer vector to 0
|
||||||
MJAPI void mju_zeroInt(int* res, int n);
|
MJAPI void mju_zeroInt(int* res, int n);
|
||||||
|
|
||||||
|
// set mjtSize vector to 0
|
||||||
|
MJAPI void mju_zeroSize(mjtSize* res, size_t n);
|
||||||
|
|
||||||
// set size_t vector to 0
|
// set size_t vector to 0
|
||||||
MJAPI void mju_zeroSizeT(size_t* res, size_t n);
|
MJAPI void mju_zeroSizeT(size_t* res, size_t n);
|
||||||
|
|
||||||
|
|||||||
@@ -728,142 +728,142 @@ public unsafe struct mjSolverStat_ {
|
|||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public unsafe struct mjData_ {
|
public unsafe struct mjData_ {
|
||||||
public UIntPtr narena;
|
public UInt64 narena;
|
||||||
public UIntPtr nbuffer;
|
public UInt64 nbuffer;
|
||||||
public int nplugin;
|
public int nplugin;
|
||||||
public UIntPtr pstack;
|
public UIntPtr pstack;
|
||||||
public UIntPtr pbase;
|
public UIntPtr pbase;
|
||||||
public UIntPtr parena;
|
public UIntPtr parena;
|
||||||
public UIntPtr maxuse_stack;
|
public UInt64 maxuse_stack;
|
||||||
public UIntPtr maxuse_threadstack0;
|
public UInt64 maxuse_threadstack0;
|
||||||
public UIntPtr maxuse_threadstack1;
|
public UInt64 maxuse_threadstack1;
|
||||||
public UIntPtr maxuse_threadstack2;
|
public UInt64 maxuse_threadstack2;
|
||||||
public UIntPtr maxuse_threadstack3;
|
public UInt64 maxuse_threadstack3;
|
||||||
public UIntPtr maxuse_threadstack4;
|
public UInt64 maxuse_threadstack4;
|
||||||
public UIntPtr maxuse_threadstack5;
|
public UInt64 maxuse_threadstack5;
|
||||||
public UIntPtr maxuse_threadstack6;
|
public UInt64 maxuse_threadstack6;
|
||||||
public UIntPtr maxuse_threadstack7;
|
public UInt64 maxuse_threadstack7;
|
||||||
public UIntPtr maxuse_threadstack8;
|
public UInt64 maxuse_threadstack8;
|
||||||
public UIntPtr maxuse_threadstack9;
|
public UInt64 maxuse_threadstack9;
|
||||||
public UIntPtr maxuse_threadstack10;
|
public UInt64 maxuse_threadstack10;
|
||||||
public UIntPtr maxuse_threadstack11;
|
public UInt64 maxuse_threadstack11;
|
||||||
public UIntPtr maxuse_threadstack12;
|
public UInt64 maxuse_threadstack12;
|
||||||
public UIntPtr maxuse_threadstack13;
|
public UInt64 maxuse_threadstack13;
|
||||||
public UIntPtr maxuse_threadstack14;
|
public UInt64 maxuse_threadstack14;
|
||||||
public UIntPtr maxuse_threadstack15;
|
public UInt64 maxuse_threadstack15;
|
||||||
public UIntPtr maxuse_threadstack16;
|
public UInt64 maxuse_threadstack16;
|
||||||
public UIntPtr maxuse_threadstack17;
|
public UInt64 maxuse_threadstack17;
|
||||||
public UIntPtr maxuse_threadstack18;
|
public UInt64 maxuse_threadstack18;
|
||||||
public UIntPtr maxuse_threadstack19;
|
public UInt64 maxuse_threadstack19;
|
||||||
public UIntPtr maxuse_threadstack20;
|
public UInt64 maxuse_threadstack20;
|
||||||
public UIntPtr maxuse_threadstack21;
|
public UInt64 maxuse_threadstack21;
|
||||||
public UIntPtr maxuse_threadstack22;
|
public UInt64 maxuse_threadstack22;
|
||||||
public UIntPtr maxuse_threadstack23;
|
public UInt64 maxuse_threadstack23;
|
||||||
public UIntPtr maxuse_threadstack24;
|
public UInt64 maxuse_threadstack24;
|
||||||
public UIntPtr maxuse_threadstack25;
|
public UInt64 maxuse_threadstack25;
|
||||||
public UIntPtr maxuse_threadstack26;
|
public UInt64 maxuse_threadstack26;
|
||||||
public UIntPtr maxuse_threadstack27;
|
public UInt64 maxuse_threadstack27;
|
||||||
public UIntPtr maxuse_threadstack28;
|
public UInt64 maxuse_threadstack28;
|
||||||
public UIntPtr maxuse_threadstack29;
|
public UInt64 maxuse_threadstack29;
|
||||||
public UIntPtr maxuse_threadstack30;
|
public UInt64 maxuse_threadstack30;
|
||||||
public UIntPtr maxuse_threadstack31;
|
public UInt64 maxuse_threadstack31;
|
||||||
public UIntPtr maxuse_threadstack32;
|
public UInt64 maxuse_threadstack32;
|
||||||
public UIntPtr maxuse_threadstack33;
|
public UInt64 maxuse_threadstack33;
|
||||||
public UIntPtr maxuse_threadstack34;
|
public UInt64 maxuse_threadstack34;
|
||||||
public UIntPtr maxuse_threadstack35;
|
public UInt64 maxuse_threadstack35;
|
||||||
public UIntPtr maxuse_threadstack36;
|
public UInt64 maxuse_threadstack36;
|
||||||
public UIntPtr maxuse_threadstack37;
|
public UInt64 maxuse_threadstack37;
|
||||||
public UIntPtr maxuse_threadstack38;
|
public UInt64 maxuse_threadstack38;
|
||||||
public UIntPtr maxuse_threadstack39;
|
public UInt64 maxuse_threadstack39;
|
||||||
public UIntPtr maxuse_threadstack40;
|
public UInt64 maxuse_threadstack40;
|
||||||
public UIntPtr maxuse_threadstack41;
|
public UInt64 maxuse_threadstack41;
|
||||||
public UIntPtr maxuse_threadstack42;
|
public UInt64 maxuse_threadstack42;
|
||||||
public UIntPtr maxuse_threadstack43;
|
public UInt64 maxuse_threadstack43;
|
||||||
public UIntPtr maxuse_threadstack44;
|
public UInt64 maxuse_threadstack44;
|
||||||
public UIntPtr maxuse_threadstack45;
|
public UInt64 maxuse_threadstack45;
|
||||||
public UIntPtr maxuse_threadstack46;
|
public UInt64 maxuse_threadstack46;
|
||||||
public UIntPtr maxuse_threadstack47;
|
public UInt64 maxuse_threadstack47;
|
||||||
public UIntPtr maxuse_threadstack48;
|
public UInt64 maxuse_threadstack48;
|
||||||
public UIntPtr maxuse_threadstack49;
|
public UInt64 maxuse_threadstack49;
|
||||||
public UIntPtr maxuse_threadstack50;
|
public UInt64 maxuse_threadstack50;
|
||||||
public UIntPtr maxuse_threadstack51;
|
public UInt64 maxuse_threadstack51;
|
||||||
public UIntPtr maxuse_threadstack52;
|
public UInt64 maxuse_threadstack52;
|
||||||
public UIntPtr maxuse_threadstack53;
|
public UInt64 maxuse_threadstack53;
|
||||||
public UIntPtr maxuse_threadstack54;
|
public UInt64 maxuse_threadstack54;
|
||||||
public UIntPtr maxuse_threadstack55;
|
public UInt64 maxuse_threadstack55;
|
||||||
public UIntPtr maxuse_threadstack56;
|
public UInt64 maxuse_threadstack56;
|
||||||
public UIntPtr maxuse_threadstack57;
|
public UInt64 maxuse_threadstack57;
|
||||||
public UIntPtr maxuse_threadstack58;
|
public UInt64 maxuse_threadstack58;
|
||||||
public UIntPtr maxuse_threadstack59;
|
public UInt64 maxuse_threadstack59;
|
||||||
public UIntPtr maxuse_threadstack60;
|
public UInt64 maxuse_threadstack60;
|
||||||
public UIntPtr maxuse_threadstack61;
|
public UInt64 maxuse_threadstack61;
|
||||||
public UIntPtr maxuse_threadstack62;
|
public UInt64 maxuse_threadstack62;
|
||||||
public UIntPtr maxuse_threadstack63;
|
public UInt64 maxuse_threadstack63;
|
||||||
public UIntPtr maxuse_threadstack64;
|
public UInt64 maxuse_threadstack64;
|
||||||
public UIntPtr maxuse_threadstack65;
|
public UInt64 maxuse_threadstack65;
|
||||||
public UIntPtr maxuse_threadstack66;
|
public UInt64 maxuse_threadstack66;
|
||||||
public UIntPtr maxuse_threadstack67;
|
public UInt64 maxuse_threadstack67;
|
||||||
public UIntPtr maxuse_threadstack68;
|
public UInt64 maxuse_threadstack68;
|
||||||
public UIntPtr maxuse_threadstack69;
|
public UInt64 maxuse_threadstack69;
|
||||||
public UIntPtr maxuse_threadstack70;
|
public UInt64 maxuse_threadstack70;
|
||||||
public UIntPtr maxuse_threadstack71;
|
public UInt64 maxuse_threadstack71;
|
||||||
public UIntPtr maxuse_threadstack72;
|
public UInt64 maxuse_threadstack72;
|
||||||
public UIntPtr maxuse_threadstack73;
|
public UInt64 maxuse_threadstack73;
|
||||||
public UIntPtr maxuse_threadstack74;
|
public UInt64 maxuse_threadstack74;
|
||||||
public UIntPtr maxuse_threadstack75;
|
public UInt64 maxuse_threadstack75;
|
||||||
public UIntPtr maxuse_threadstack76;
|
public UInt64 maxuse_threadstack76;
|
||||||
public UIntPtr maxuse_threadstack77;
|
public UInt64 maxuse_threadstack77;
|
||||||
public UIntPtr maxuse_threadstack78;
|
public UInt64 maxuse_threadstack78;
|
||||||
public UIntPtr maxuse_threadstack79;
|
public UInt64 maxuse_threadstack79;
|
||||||
public UIntPtr maxuse_threadstack80;
|
public UInt64 maxuse_threadstack80;
|
||||||
public UIntPtr maxuse_threadstack81;
|
public UInt64 maxuse_threadstack81;
|
||||||
public UIntPtr maxuse_threadstack82;
|
public UInt64 maxuse_threadstack82;
|
||||||
public UIntPtr maxuse_threadstack83;
|
public UInt64 maxuse_threadstack83;
|
||||||
public UIntPtr maxuse_threadstack84;
|
public UInt64 maxuse_threadstack84;
|
||||||
public UIntPtr maxuse_threadstack85;
|
public UInt64 maxuse_threadstack85;
|
||||||
public UIntPtr maxuse_threadstack86;
|
public UInt64 maxuse_threadstack86;
|
||||||
public UIntPtr maxuse_threadstack87;
|
public UInt64 maxuse_threadstack87;
|
||||||
public UIntPtr maxuse_threadstack88;
|
public UInt64 maxuse_threadstack88;
|
||||||
public UIntPtr maxuse_threadstack89;
|
public UInt64 maxuse_threadstack89;
|
||||||
public UIntPtr maxuse_threadstack90;
|
public UInt64 maxuse_threadstack90;
|
||||||
public UIntPtr maxuse_threadstack91;
|
public UInt64 maxuse_threadstack91;
|
||||||
public UIntPtr maxuse_threadstack92;
|
public UInt64 maxuse_threadstack92;
|
||||||
public UIntPtr maxuse_threadstack93;
|
public UInt64 maxuse_threadstack93;
|
||||||
public UIntPtr maxuse_threadstack94;
|
public UInt64 maxuse_threadstack94;
|
||||||
public UIntPtr maxuse_threadstack95;
|
public UInt64 maxuse_threadstack95;
|
||||||
public UIntPtr maxuse_threadstack96;
|
public UInt64 maxuse_threadstack96;
|
||||||
public UIntPtr maxuse_threadstack97;
|
public UInt64 maxuse_threadstack97;
|
||||||
public UIntPtr maxuse_threadstack98;
|
public UInt64 maxuse_threadstack98;
|
||||||
public UIntPtr maxuse_threadstack99;
|
public UInt64 maxuse_threadstack99;
|
||||||
public UIntPtr maxuse_threadstack100;
|
public UInt64 maxuse_threadstack100;
|
||||||
public UIntPtr maxuse_threadstack101;
|
public UInt64 maxuse_threadstack101;
|
||||||
public UIntPtr maxuse_threadstack102;
|
public UInt64 maxuse_threadstack102;
|
||||||
public UIntPtr maxuse_threadstack103;
|
public UInt64 maxuse_threadstack103;
|
||||||
public UIntPtr maxuse_threadstack104;
|
public UInt64 maxuse_threadstack104;
|
||||||
public UIntPtr maxuse_threadstack105;
|
public UInt64 maxuse_threadstack105;
|
||||||
public UIntPtr maxuse_threadstack106;
|
public UInt64 maxuse_threadstack106;
|
||||||
public UIntPtr maxuse_threadstack107;
|
public UInt64 maxuse_threadstack107;
|
||||||
public UIntPtr maxuse_threadstack108;
|
public UInt64 maxuse_threadstack108;
|
||||||
public UIntPtr maxuse_threadstack109;
|
public UInt64 maxuse_threadstack109;
|
||||||
public UIntPtr maxuse_threadstack110;
|
public UInt64 maxuse_threadstack110;
|
||||||
public UIntPtr maxuse_threadstack111;
|
public UInt64 maxuse_threadstack111;
|
||||||
public UIntPtr maxuse_threadstack112;
|
public UInt64 maxuse_threadstack112;
|
||||||
public UIntPtr maxuse_threadstack113;
|
public UInt64 maxuse_threadstack113;
|
||||||
public UIntPtr maxuse_threadstack114;
|
public UInt64 maxuse_threadstack114;
|
||||||
public UIntPtr maxuse_threadstack115;
|
public UInt64 maxuse_threadstack115;
|
||||||
public UIntPtr maxuse_threadstack116;
|
public UInt64 maxuse_threadstack116;
|
||||||
public UIntPtr maxuse_threadstack117;
|
public UInt64 maxuse_threadstack117;
|
||||||
public UIntPtr maxuse_threadstack118;
|
public UInt64 maxuse_threadstack118;
|
||||||
public UIntPtr maxuse_threadstack119;
|
public UInt64 maxuse_threadstack119;
|
||||||
public UIntPtr maxuse_threadstack120;
|
public UInt64 maxuse_threadstack120;
|
||||||
public UIntPtr maxuse_threadstack121;
|
public UInt64 maxuse_threadstack121;
|
||||||
public UIntPtr maxuse_threadstack122;
|
public UInt64 maxuse_threadstack122;
|
||||||
public UIntPtr maxuse_threadstack123;
|
public UInt64 maxuse_threadstack123;
|
||||||
public UIntPtr maxuse_threadstack124;
|
public UInt64 maxuse_threadstack124;
|
||||||
public UIntPtr maxuse_threadstack125;
|
public UInt64 maxuse_threadstack125;
|
||||||
public UIntPtr maxuse_threadstack126;
|
public UInt64 maxuse_threadstack126;
|
||||||
public UIntPtr maxuse_threadstack127;
|
public UInt64 maxuse_threadstack127;
|
||||||
public UIntPtr maxuse_arena;
|
public UInt64 maxuse_arena;
|
||||||
public int maxuse_con;
|
public int maxuse_con;
|
||||||
public int maxuse_efc;
|
public int maxuse_efc;
|
||||||
public mjSolverStat_ solver0;
|
public mjSolverStat_ solver0;
|
||||||
@@ -5341,8 +5341,8 @@ public unsafe struct mjModel_ {
|
|||||||
public int nuserdata;
|
public int nuserdata;
|
||||||
public int nsensordata;
|
public int nsensordata;
|
||||||
public int npluginstate;
|
public int npluginstate;
|
||||||
public UIntPtr narena;
|
public UInt64 narena;
|
||||||
public UIntPtr nbuffer;
|
public UInt64 nbuffer;
|
||||||
public mjOption_ opt;
|
public mjOption_ opt;
|
||||||
public mjVisual_ vis;
|
public mjVisual_ vis;
|
||||||
public mjStatistic_ stat;
|
public mjStatistic_ stat;
|
||||||
|
|||||||
Reference in New Issue
Block a user