Merge pull request #2730 from janisozaur/config

Release config on closing to limit leaked memory
This commit is contained in:
Ted John 2016-01-15 20:12:29 +00:00
commit 36513c9431
8 changed files with 47 additions and 3 deletions

View File

@ -396,6 +396,21 @@ void config_set_defaults()
}
}
void config_release()
{
for (int i = 0; i < countof(_sectionDefinitions); i++) {
config_section_definition *section = &_sectionDefinitions[i];
for (int j = 0; j < section->property_definitions_count; j++) {
config_property_definition *property = &section->property_definitions[j];
value_union *destValue = (value_union*)((size_t)section->base_address + (size_t)property->offset);
if (property->type == CONFIG_VALUE_TYPE_STRING) {
utf8 **dst = (utf8**)&(destValue->value_string);
SafeFree(*dst);
}
}
}
}
void config_get_default_path(utf8 *outPath)
{
platform_get_user_directory(outPath, NULL);

View File

@ -339,6 +339,7 @@ extern uint16 gShortcutKeys[SHORTCUT_COUNT];
void config_get_default_path(utf8 *outPath);
void config_set_defaults();
void config_release();
bool config_open_default();
bool config_save_default();

View File

@ -120,6 +120,8 @@ void gfx_fill_rect_inset(rct_drawpixelinfo* dpi, short left, short top, short ri
// sprite
int gfx_load_g1();
int gfx_load_g2();
void gfx_unload_g1();
void gfx_unload_g2();
void sub_68371D();
void gfx_bmp_sprite_to_buffer(uint8* palette_pointer, uint8* unknown_pointer, uint8* source_pointer, uint8* dest_pointer, rct_g1_element* source_image, rct_drawpixelinfo *dest_dpi, int height, int width, int image_type);
void gfx_rle_sprite_to_buffer(const uint8* source_bits_pointer, uint8* dest_bits_pointer, const uint8* palette_pointer, const rct_drawpixelinfo *dpi, int image_type, int source_y_start, int height, int source_x_start, int width);

View File

@ -74,6 +74,16 @@ int gfx_load_g1()
return 0;
}
void gfx_unload_g1()
{
SafeFree(_g1Buffer);
}
void gfx_unload_g2()
{
SafeFree(g2.elements);
}
int gfx_load_g2()
{
log_verbose("loading g2 graphics");

View File

@ -171,18 +171,24 @@ void colour_scheme_update_by_class(rct_window *window, rct_windowclass classific
window->flags |= WF_TRANSPARENT;
}
static void theme_set_preset_string(const utf8string preset)
{
SafeFree(gConfigInterface.current_theme_preset);
gConfigInterface.current_theme_preset = strdup(preset);
}
void theme_change_preset(int preset)
{
if (preset >= 0 && preset < gConfigThemes.num_presets) {
switch (preset) {
case 0:
gConfigInterface.current_theme_preset = "*RCT2";
theme_set_preset_string("*RCT2");
break;
case 1:
gConfigInterface.current_theme_preset = "*RCT1";
theme_set_preset_string("*RCT1");
break;
default:
gConfigInterface.current_theme_preset = gConfigThemes.presets[preset].name;
theme_set_preset_string(gConfigThemes.presets[preset].name);
break;
}
gCurrentTheme = preset;

View File

@ -322,6 +322,8 @@ void openrct2_dispose()
network_close();
http_dispose();
language_close_all();
rct2_dispose();
config_release();
platform_free();
}

View File

@ -126,6 +126,13 @@ void rct2_quit()
window_save_prompt_open();
}
void rct2_dispose()
{
gfx_unload_g2();
gfx_unload_g1();
object_unload_all();
}
int rct2_init()
{
log_verbose("initialising game");

View File

@ -261,6 +261,7 @@ extern const char * const RCT2FilePaths[PATH_ID_END];
extern uint32 gCurrentDrawCount;
int rct2_init();
void rct2_dispose();
void rct2_update();
void rct2_draw();
void substitute_path(char *dest, const char *path, const char *filename);