Skip to content

Commit a46a111

Browse files
authored
Merge pull request #278 from zeux/file-release-size
2 parents ebf875e + 117df4f commit a46a111

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cgltf.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct cgltf_memory_options
141141
typedef struct cgltf_file_options
142142
{
143143
cgltf_result(*read)(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, const char* path, cgltf_size* size, void** data);
144-
void (*release)(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, void* data);
144+
void (*release)(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, void* data, cgltf_size size);
145145
void* user_data;
146146
} cgltf_file_options;
147147

@@ -769,6 +769,7 @@ typedef struct cgltf_data
769769
{
770770
cgltf_file_type file_type;
771771
void* file_data;
772+
cgltf_size file_size;
772773

773774
cgltf_asset asset;
774775

@@ -1099,9 +1100,10 @@ static cgltf_result cgltf_default_file_read(const struct cgltf_memory_options* m
10991100
return cgltf_result_success;
11001101
}
11011102

1102-
static void cgltf_default_file_release(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, void* data)
1103+
static void cgltf_default_file_release(const struct cgltf_memory_options* memory_options, const struct cgltf_file_options* file_options, void* data, cgltf_size size)
11031104
{
11041105
(void)file_options;
1106+
(void)size;
11051107
void (*memfree)(void*, void*) = memory_options->free_func ? memory_options->free_func : &cgltf_default_free;
11061108
memfree(memory_options->user_data, data);
11071109
}
@@ -1248,7 +1250,7 @@ cgltf_result cgltf_parse_file(const cgltf_options* options, const char* path, cg
12481250
}
12491251

12501252
cgltf_result (*file_read)(const struct cgltf_memory_options*, const struct cgltf_file_options*, const char*, cgltf_size*, void**) = options->file.read ? options->file.read : &cgltf_default_file_read;
1251-
void (*file_release)(const struct cgltf_memory_options*, const struct cgltf_file_options*, void* data) = options->file.release ? options->file.release : cgltf_default_file_release;
1253+
void (*file_release)(const struct cgltf_memory_options*, const struct cgltf_file_options*, void* data, cgltf_size size) = options->file.release ? options->file.release : cgltf_default_file_release;
12521254

12531255
void* file_data = NULL;
12541256
cgltf_size file_size = 0;
@@ -1262,11 +1264,12 @@ cgltf_result cgltf_parse_file(const cgltf_options* options, const char* path, cg
12621264

12631265
if (result != cgltf_result_success)
12641266
{
1265-
file_release(&options->memory, &options->file, file_data);
1267+
file_release(&options->memory, &options->file, file_data, file_size);
12661268
return result;
12671269
}
12681270

12691271
(*out_data)->file_data = file_data;
1272+
(*out_data)->file_size = file_size;
12701273

12711274
return cgltf_result_success;
12721275
}
@@ -1850,7 +1853,7 @@ void cgltf_free(cgltf_data* data)
18501853
return;
18511854
}
18521855

1853-
void (*file_release)(const struct cgltf_memory_options*, const struct cgltf_file_options*, void* data) = data->file.release ? data->file.release : cgltf_default_file_release;
1856+
void (*file_release)(const struct cgltf_memory_options*, const struct cgltf_file_options*, void* data, cgltf_size size) = data->file.release ? data->file.release : cgltf_default_file_release;
18541857

18551858
data->memory.free_func(data->memory.user_data, data->asset.copyright);
18561859
data->memory.free_func(data->memory.user_data, data->asset.generator);
@@ -1885,7 +1888,7 @@ void cgltf_free(cgltf_data* data)
18851888

18861889
if (data->buffers[i].data_free_method == cgltf_data_free_method_file_release)
18871890
{
1888-
file_release(&data->memory, &data->file, data->buffers[i].data);
1891+
file_release(&data->memory, &data->file, data->buffers[i].data, data->buffers[i].size);
18891892
}
18901893
else if (data->buffers[i].data_free_method == cgltf_data_free_method_memory_free)
18911894
{
@@ -2124,7 +2127,7 @@ void cgltf_free(cgltf_data* data)
21242127

21252128
data->memory.free_func(data->memory.user_data, data->extensions_required);
21262129

2127-
file_release(&data->memory, &data->file, data->file_data);
2130+
file_release(&data->memory, &data->file, data->file_data, data->file_size);
21282131

21292132
data->memory.free_func(data->memory.user_data, data);
21302133
}

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required( VERSION 2.8 )
1+
cmake_minimum_required(VERSION 3.5...3.30)
22

33
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
44

0 commit comments

Comments
 (0)