提示コードの///
コメント部内部のコードですがこの関数で以下のエラーが発生しますこれはなぜでしょうか?デバッガで原因を調べましたが何が原因なのかわかりません。
調べたこと。試したこと
デバッガで何が原因なのかを調べました。
///
コメント部内部の関数をコメントアウトしても実行画面を閉じると同じエラーが表示されます。
オブジェクトファイルを削除
画像ファイルは存在しています。
Game.cpp
cpp
1#include "../header/Game.hpp" 2 3Game::Game() : Actor() 4{ 5 position = glm::ivec2(100,100); 6//////////////////////////////////////////////// 7 up_sprite = FrameWork::LoadTexture("Asset/texture/up.png"); 8/////////////////////////////////////////////// 9// down_sprite = FrameWork::LoadTexture("Asset/texture/down.png"); 10// left_sprite = FrameWork::LoadTexture("Asset/texture/left.png"); 11// right_sprite = FrameWork::LoadTexture("Asset/texture/right.png"); 12} 13 14void Game::Update() 15{ 16 if(FrameWork::GetKeyInput(GLFW_KEY_UP) > 0) 17 { 18 position.y++; 19 } 20 else if(FrameWork::GetKeyInput(GLFW_KEY_DOWN) > 0) 21 { 22 position.y--; 23 } 24 else if(FrameWork::GetKeyInput(GLFW_KEY_LEFT) > 0) 25 { 26 position.x--; 27 } 28 else if(FrameWork::GetKeyInput(GLFW_KEY_RIGHT) > 0) 29 { 30 position.x++; 31 } 32 33 34 35 36} 37void Game::Renderer(const glm::mat4 view)const 38{ 39// FrameWork::Renderer_Sprite(view,right_sprite,glm::vec3(position,0),glm::ivec2(0,0),glm::ivec2(64,32)); 40} 41 42Game::~Game() 43{ 44 45} 46
Resource.cpp
cpp
1 2// ##################################### テクスチャをロード ##################################### 3FrameWork::Texture FrameWork::LoadTexture(const char* fileName) 4{ 5 Texture texture; 6 7 glm::ivec2 size; 8 int channel; 9 10 unsigned char* data = NULL; 11 data = stbi_load(fileName, &size.x, &size.y, &channel, 0); 12 13 texture.size = size; 14 15 if (data == NULL) 16 { 17 std::cerr << "画像が見つかりません: " << fileName << std::endl; 18 assert(0); 19 } 20 21 glGenTextures(1, &texture.ID); //テクスチャIDの生成 22 23 glBindTexture(GL_TEXTURE_2D, texture.ID); // IDバインド 24 25 //テクスチャ生成 26 27 if (channel == 4) 28 { 29 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); 30 } 31 else if (channel == 3) 32 { 33 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.x, size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, data); 34 } 35 else if (channel == 2) 36 { 37 glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, size.x, size.y, 0, GL_RG, GL_UNSIGNED_BYTE, data); 38 } 39 else if (channel == 1) 40 { 41 glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, size.x, size.y, 0, GL_RED, GL_UNSIGNED_BYTE, data); 42 } 43 else 44 { 45 std::cerr << "未対応の形式のチャンネル数です: " << fileName <<" "<< "チャンネル数: "<<channel<< std::endl; 46 assert(0); 47 } 48 49 // テクスチャの補間設定 50 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 51 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 52 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 53 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 54 glGenerateMipmap(GL_TEXTURE_2D); 55 glBindTexture(GL_TEXTURE_2D, 0); 56 57 stbi_image_free(data); 58 59 return texture; 60 61}
Console
console
1shigurechan@shigurechan-System-Product-Name:~/prg/TopDownGame$ gdb ./Game 2GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2 3Copyright (C) 2020 Free Software Foundation, Inc. 4License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 5This is free software: you are free to change and redistribute it. 6There is NO WARRANTY, to the extent permitted by law. 7Type "show copying" and "show warranty" for details. 8This GDB was configured as "x86_64-linux-gnu". 9Type "show configuration" for configuration details. 10For bug reporting instructions, please see: 11<http://www.gnu.org/software/gdb/bugs/>. 12Find the GDB manual and other documentation resources online at: 13 <http://www.gnu.org/software/gdb/documentation/>. 14 15For help, type "help". 16Type "apropos word" to search for commands related to "word"... 17Reading symbols from ./Game... 18(gdb) run 19Starting program: /home/shigurechan/prg/TopDownGame/Game 20[Thread debugging using libthread_db enabled] 21Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 22[New Thread 0x7fffec8fb700 (LWP 20806)] 23[New Thread 0x7fffe7fff700 (LWP 20807)] 24 25Thread 1 "Game" received signal SIGSEGV, Segmentation fault. 260x00007ffff78f08a2 in __GI___libc_free (mem=<optimized out>) at malloc.c:3124 273124 malloc.c: そのようなファイルやディレクトリはありません. 28(gdb) bt 29#0 0x00007ffff78f08a2 in __GI___libc_free (mem=<optimized out>) at malloc.c:3124 30#1 0x00007ffff761301d in _XReply () from /lib/x86_64-linux-gnu/libX11.so.6 31#2 0x00007ffff76100ed in XTranslateCoordinates () from /lib/x86_64-linux-gnu/libX11.so.6 32#3 0x00005555555b38a0 in processEvent () 33#4 0x00005555555b6f77 in _glfwPollEventsX11 () 34#5 0x00005555555a7b4b in glfwPollEvents () 35#6 0x0000555555596179 in FrameWork::Window::operator bool (this=0x5555557b1c30) at FrameWork/source/Window.cpp:316 36#7 0x000055555559c108 in main () at source/Main.cpp:30 37(gdb) run 38The program being debugged has been started already. 39Start it from the beginning? (y or n) y 40Starting program: /home/shigurechan/prg/TopDownGame/Game 41[Thread debugging using libthread_db enabled] 42Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". 43[New Thread 0x7fffec8fb700 (LWP 20810)] 44[New Thread 0x7fffe7fff700 (LWP 20811)] 45 46Thread 1 "Game" received signal SIGSEGV, Segmentation fault. 470x00007ffff78f08a2 in __GI___libc_free (mem=<optimized out>) at malloc.c:3124 483124 malloc.c: そのようなファイルやディレクトリはありません. 49(gdb) bt 50#0 0x00007ffff78f08a2 in __GI___libc_free (mem=<optimized out>) at malloc.c:3124 51#1 0x00007ffff761301d in _XReply () from /lib/x86_64-linux-gnu/libX11.so.6 52#2 0x00007ffff76100ed in XTranslateCoordinates () from /lib/x86_64-linux-gnu/libX11.so.6 53#3 0x00005555555b38a0 in processEvent () 54#4 0x00005555555b6f77 in _glfwPollEventsX11 () 55#5 0x00005555555a7b4b in glfwPollEvents () 56#6 0x0000555555596179 in FrameWork::Window::operator bool (this=0x5555557b1c30) at FrameWork/source/Window.cpp:316 57#7 0x000055555559c108 in main () at source/Main.cpp:30 58(gdb) quit 59A debugging session is active. 60 61 Inferior 1 [process 20808] will be killed. 62 63Quit anyway? (y or n) y 64shigurechan@shigurechan-System-Product-Name:~/prg/TopDownGame$ ./Game 65Segmentation fault (コアダンプ) 66shigurechan@shigurechan-System-Product-Name:~/prg/TopDownGame$ 67 68
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。