A memory error... not very specific

Started by Animus_Surge, December 05, 2019, 04:08:56

Previous topic - Next topic

Animus_Surge

Sorry for the double post, I would have put this in my other one, but I don't know if this is relevent to that topic now.

I am having memory issues with my Image class I had mentioned in my other one. The image renders just fine now... but only for about 25 seconds, then it crashes with the following log. NOTE: I am using lwjglx-debug with this.

{[filesys|INFO   ]: Settings loaded.}
[LWJGL] Version: 3.2.3 build 13
[LWJGL] 	 OS: Windows 10 v10.0
[LWJGL] 	JRE: 13.0.1 amd64
[LWJGL] 	JVM: Java HotSpot(TM) 64-Bit Server VM v13.0.1+9 by Oracle Corporation
[LWJGL] Loading JNI library: lwjgl
[LWJGL] 	Module: org.lwjgl
[LWJGL] 	Using SharedLibraryLoader...
[LWJGL] 	Found at: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl.dll
[LWJGL] 	Found at: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl.dll
[LWJGL] Loading library: glfw
[LWJGL] 	Module: org.lwjgl.glfw
[LWJGL] 	Using SharedLibraryLoader...
[LWJGL] 	Found at: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\glfw.dll
[LWJGL] Java 9 stack walker enabled
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\glfw.dll
[LWJGL] Loading library: jemalloc
[LWJGL] 	Module: org.lwjgl.jemalloc
[LWJGL] 	Using SharedLibraryLoader...
[LWJGL] 	Found at: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\jemalloc.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\jemalloc.dll
[LWJGL] MemoryUtil allocator: DebugAllocator
{[window|INFO   ]: GLFW initialized.}
{[window|INFO   ]: Window initialized. Creating graphics buffers...}
[LWJGL] Loading JNI library: lwjgl_opengl
[LWJGL] 	Module: org.lwjgl.opengl
[LWJGL] 	Using SharedLibraryLoader...
[LWJGL] 	Found at: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl_opengl.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl_opengl.dll
[LWJGL] Loading library: opengl32
[LWJGL] 	Module: org.lwjgl.opengl
[LWJGL] 	opengl32.dll not found in org.lwjgl.librarypath=C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13
[LWJGL] 	Loaded from system paths: C:\WINDOWS\SYSTEM32\opengl32.dll
[LWJGL] Java 10 multiplyHigh enabled
[LWJGL] Java 9 check intrinsics enabled
[LWJGL] Java 10 memcpy enabled
[LWJGL] [GL] Using OpenGL 4.3 for error logging.
[LWJGL] Java 9 text decoding enabled
[info ][1] Initialized OpenGL context for window[1]
  Effective OpenGL version: 4.5
  OpenGL version string   : 4.5.0 - Build 24.20.100.6292
  OpenGL vendor           : Intel
  OpenGL renderer         : Intel(R) HD Graphics 620
  GL_MAX_VERTEX_ATTRIBS   : 16
  Capabilities:
        1      GL_AMD_depth_clamp_separate GL_AMD_vertex_shader_layer 
        2      GL_AMD_vertex_shader_viewport_index GL_ARB_arrays_of_arrays 
        3      GL_ARB_base_instance GL_ARB_bindless_texture GL_ARB_blend_func_extended 
        4      GL_ARB_buffer_storage GL_ARB_cl_event GL_ARB_clear_buffer_object 
        5      GL_ARB_clear_texture GL_ARB_clip_control GL_ARB_color_buffer_float 
        6      GL_ARB_compatibility GL_ARB_compressed_texture_pixel_storage 
        7      GL_ARB_compute_shader GL_ARB_conditional_render_inverted 
        8      GL_ARB_conservative_depth GL_ARB_copy_buffer GL_ARB_copy_image 
        9      GL_ARB_cull_distance GL_ARB_debug_output GL_ARB_depth_buffer_float 
       10      GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_derivative_control 
       11      GL_ARB_direct_state_access GL_ARB_draw_buffers GL_ARB_draw_buffers_blend 
       12      GL_ARB_draw_elements_base_vertex GL_ARB_draw_indirect GL_ARB_draw_instanced 
       13      GL_ARB_enhanced_layouts GL_ARB_ES2_compatibility GL_ARB_ES3_1_compatibility 
       14      GL_ARB_ES3_compatibility GL_ARB_explicit_attrib_location 
       15      GL_ARB_explicit_uniform_location GL_ARB_fragment_coord_conventions 
       16      GL_ARB_fragment_layer_viewport GL_ARB_fragment_program 
       17      GL_ARB_fragment_program_shadow GL_ARB_fragment_shader 
       18      GL_ARB_fragment_shader_interlock GL_ARB_framebuffer_no_attachments 
       19      GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 
       20      GL_ARB_get_program_binary GL_ARB_get_texture_sub_image GL_ARB_gpu_shader5 
       21      GL_ARB_gpu_shader_fp64 GL_ARB_half_float_pixel GL_ARB_half_float_vertex 
       22      GL_ARB_indirect_parameters GL_ARB_instanced_arrays GL_ARB_internalformat_query 
       23      GL_ARB_internalformat_query2 GL_ARB_invalidate_subdata 
       24      GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multi_bind 
       25      GL_ARB_multi_draw_indirect GL_ARB_multisample GL_ARB_multitexture 
       26      GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object 
       27      GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_polygon_offset_clamp 
       28      GL_ARB_post_depth_coverage GL_ARB_program_interface_query 
       29      GL_ARB_provoking_vertex GL_ARB_query_buffer_object 
       30      GL_ARB_robust_buffer_access_behavior GL_ARB_robustness GL_ARB_sample_shading 
       31      GL_ARB_sampler_objects GL_ARB_seamless_cube_map 
       32      GL_ARB_seamless_cubemap_per_texture GL_ARB_separate_shader_objects 
       33      GL_ARB_shader_atomic_counter_ops GL_ARB_shader_atomic_counters 
       34      GL_ARB_shader_bit_encoding GL_ARB_shader_draw_parameters 
       35      GL_ARB_shader_group_vote GL_ARB_shader_image_load_store 
       36      GL_ARB_shader_image_size GL_ARB_shader_objects GL_ARB_shader_precision 
       37      GL_ARB_shader_stencil_export GL_ARB_shader_storage_buffer_object 
       38      GL_ARB_shader_subroutine GL_ARB_shader_texture_image_samples 
       39      GL_ARB_shading_language_100 GL_ARB_shading_language_420pack 
       40      GL_ARB_shading_language_packing GL_ARB_shadow GL_ARB_stencil_texturing 
       41      GL_ARB_sync GL_ARB_tessellation_shader GL_ARB_texture_barrier 
       42      GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object 
       43      GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_buffer_range 
       44      GL_ARB_texture_compression GL_ARB_texture_compression_bptc 
       45      GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map 
       46      GL_ARB_texture_cube_map_array GL_ARB_texture_env_add GL_ARB_texture_env_combine 
       47      GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float 
       48      GL_ARB_texture_gather GL_ARB_texture_mirror_clamp_to_edge 
       49      GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample 
       50      GL_ARB_texture_non_power_of_two GL_ARB_texture_query_levels 
       51      GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg 
       52      GL_ARB_texture_rgb10_a2ui GL_ARB_texture_stencil8 GL_ARB_texture_storage 
       53      GL_ARB_texture_storage_multisample GL_ARB_texture_swizzle GL_ARB_texture_view 
       54      GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 
       55      GL_ARB_transform_feedback_instanced GL_ARB_transpose_matrix 
       56      GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra 
       57      GL_ARB_vertex_array_object GL_ARB_vertex_attrib_64bit 
       58      GL_ARB_vertex_attrib_binding GL_ARB_vertex_buffer_object GL_ARB_vertex_program 
       59      GL_ARB_vertex_shader GL_ARB_vertex_type_10f_11f_11f_rev 
       60      GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos 
       61      GL_EXT_abgr GL_EXT_bgra GL_EXT_blend_color GL_EXT_blend_equation_separate 
       62      GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract 
       63      GL_EXT_clip_volume_hint GL_EXT_compiled_vertex_array GL_EXT_direct_state_access 
       64      GL_EXT_draw_buffers2 GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample 
       65      GL_EXT_framebuffer_object GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters 
       66      GL_EXT_gpu_shader4 GL_EXT_packed_depth_stencil GL_EXT_packed_float 
       67      GL_EXT_polygon_offset_clamp GL_EXT_secondary_color 
       68      GL_EXT_shader_framebuffer_fetch GL_EXT_shader_integer_mix GL_EXT_shadow_funcs 
       69      GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture_array 
       70      GL_EXT_texture_compression_s3tc GL_EXT_texture_filter_anisotropic 
       71      GL_EXT_texture_integer GL_EXT_texture_shared_exponent GL_EXT_texture_snorm 
       72      GL_EXT_texture_sRGB GL_EXT_texture_sRGB_decode GL_EXT_texture_swizzle 
       73      GL_EXT_timer_query GL_EXT_transform_feedback 
       74      GL_INTEL_conservative_rasterization GL_INTEL_fragment_shader_ordering 
       75      GL_INTEL_framebuffer_CMAA GL_INTEL_map_texture GL_INTEL_performance_query 
       76      GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent 
       77      GL_KHR_context_flush_control GL_KHR_debug GL_KHR_texture_compression_astc_hdr 
       78      GL_KHR_texture_compression_astc_ldr GL_NV_blend_square GL_NV_conditional_render 
       79      GL_NV_primitive_restart GL_NV_texgen_reflection 
[LWJGL] Loading JNI library: lwjgl_stb
[LWJGL] 	Module: org.lwjgl.stb
[LWJGL] 	Using SharedLibraryLoader...
[LWJGL] 	Found at: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl_stb.dll
[LWJGL] 	Loaded from org.lwjgl.librarypath: C:\Users\1645522\AppData\Local\Temp\lwjgl1645522\3.2.3-build-13\lwjgl_stb.dll
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 13631488 bytes for Failed to commit area from 0x00000000c5e00000 to 0x00000000c6b00000 of length 13631488.
# An error report file with more information is saved as:
# C:\Users\1645522\Desktop\Wings-of-Fire-the-RPG\hs_err_pid2448.log
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5e00000, 13631488, 0) failed; error='The paging file is too small for this operation to complete' (DOS error/errno=1455)

Process finished with exit code 1


I can normally read errors and resolve them, but this is too vague for me to read... and I normally read stacktraces instead of debug logs. The code for the class is below:

package com.programwings.wofrpg.display.drawable;

import static org.lwjgl.opengl.GL11.*;

import com.programwings.wofrpg.util.Coordinate;
import org.lwjgl.BufferUtils;
import org.lwjgl.stb.STBImage;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

public class Image {

	private int id, width, height;
	private Coordinate c1, c2, c3, c4;
	private String file;

	public Image(String filename) {
		file = filename;
		this.c1 = new Coordinate(1, 1);
		this.c2 = new Coordinate(-1, 1);
		this.c3 = new Coordinate(-1, -1);
		this.c4 = new Coordinate(1, -1);

		IntBuffer wid = BufferUtils.createIntBuffer(1);
		IntBuffer hei = BufferUtils.createIntBuffer(1);
		IntBuffer com = BufferUtils.createIntBuffer(1);

		ByteBuffer data = STBImage.stbi_load(filename, wid, hei, com, 4);

		id = glGenTextures();
		width = wid.get();
		height = hei.get();
		bind();

		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
		//STBImage.stbi_image_free(data);
	}

	public Image(String filename, Coordinate c1, Coordinate c2, Coordinate c3, Coordinate c4) {
		file = filename;
		this.c1 = c1;
		this.c2 = c2;
		this.c3 = c3;
		this.c4 = c4;

		IntBuffer wid = BufferUtils.createIntBuffer(1);
		IntBuffer hei = BufferUtils.createIntBuffer(1);
		IntBuffer com = BufferUtils.createIntBuffer(1);

		ByteBuffer data = STBImage.stbi_load(filename, wid, hei, com, 4);

		id = glGenTextures();
		width = wid.get();
		height = hei.get();
		bind();

		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
		STBImage.stbi_image_free(data);
	}

	public void bind() {
		glBindTexture(GL_TEXTURE_2D, id);
	}

	public void unbind() {
		glBindTexture(GL_TEXTURE_2D, 0);
	}

	public void setFileName(String fileName) {
		this.file = fileName;
	}

	public void draw() {
		bind();
		glEnable(GL_TEXTURE_2D);
		glBegin(GL_QUADS);
			glTexCoord2d(1, 0);
			glVertex2d(c1.x, c1.y);
			glTexCoord2d(0, 0);
			glVertex2d(c2.x, c2.y);
			glTexCoord2d(0, 1);
			glVertex2d(c3.x, c3.y);
			glTexCoord2d(1, 1);
			glVertex2d(c4.x, c4.y);
		glEnd();
		unbind();
	}


}


Here are some technical specs for the computer that I'm using at the moment in case this is relevent:

Model: Dell latitude 3300
RAM: 4gb
CPU: Intel core i3-7th gen
GPU: Intel integrated graphics
Storage: 128 gb solid state drive

KaiHH

Quote
There is insufficient memory for the Java Runtime Environment to continue.
The paging file is too small for this operation to complete
This means: The process cannot allocate any more memory.
Which means you have exhausted your process'es virtual memory space, which means: You have a memory leak.
You likely allocate native memory every frame without deallocating it.
Keep in mind that memory allocated through LWJGL3's MemoryUtil will not automatically be garbage collected.
Probably also read this: https://blog.lwjgl.org/memory-management-in-lwjgl-3/

Animus_Surge

Quote
(0)You have a memory leak.
(1)You likely allocate native memory every frame without deallocating it.
(2)Keep in mind that memory allocated through LWJGL3's MemoryUtil will not automatically be garbage collected.

0:
Hmmm... alright, so I have no clue how that impacts performance in LWJGL

1:
Okay, so how do I deallocate it? (I'm still relatively new to images in LWJGL)

2: Alright, I'll do my best

Animus_Surge

I solved my problem... I had to rewrite my entire driver and I had forgotten to add the
STBImage.stbi_image_free();
method in my two constructors. Everything works fine now.