简体   繁体   English

SFML 2.1程序在调试模式下运行良好,但在发布模式下崩溃

[英]SFML 2.1 program runs fine in debug mode, but crashes in release mode

I am using Qt Creator for an SFML project. 我正在将Qt Creator用于SFML项目。 The problem I am currently experiencing is that my application will crash on a certain line of code only if I am running in release mode. 我当前遇到的问题是, 仅当我在发布模式下运行时,我的应用程序才会在特定的代码行上崩溃。

I've stripped down my application to find the exact line of code that is causing the problem. 我已经精简了我的应用程序,以查找导致问题的确切代码行。 Here is what my entire program looks like: 这是我的整个程序的样子:

Works in Debug Mode; 在调试模式下工作; Crashes in Release Mode 在发布模式下崩溃

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Worked!");
    window.setVerticalSyncEnabled(true);

    sf::Shader shader;
    shader.loadFromFile("data\\shaders\\HorizontalBlur.frag", sf::Shader::Fragment);

    return 0;
}

If I remove the loadFromFile code, then it will run fine in both debug and release modes. 如果删除loadFromFile代码,则它将在调试和发布模式下都可以正常运行。

Works in Debug Mode; 在调试模式下工作; Works in Release Mode 在发布模式下工作

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Worked!");
    window.setVerticalSyncEnabled(true);

    sf::Shader shader;
    //shader.loadFromFile("data\\shaders\\HorizontalBlur.frag", sf::Shader::Fragment);

    return 0;
}

My system looks like this: 我的系统如下所示:

  • Windows 8 64-bit Windows 8 64位
  • Qt Creator 2.8.1 Qt Creator 2.8.1
  • GCC 4.8 GCC 4.8
  • SFML 2.1 compiled with GCC 4.8 使用GCC 4.8编译的SFML 2.1

I'm looking for your suggestions and guidance to help me figure out what would cause this line of code to work in debug mode, but not in release mode. 我正在寻找您的建议和指导,以帮助我找出导致此代码行在调试模式下工作的原因,而不是在发布模式下工作的原因。

Thank you! 谢谢! :) :)

Update #1 更新#1

I am using qmake for this project. 我正在为此项目使用qmake。 It creates three make files: 它创建三个生成文件:

  • Makefile 生成文件
  • Makefile.debug Makefile.debug
  • Makefile.release Makefile.release

I'm not very experienced with makefiles, but I can see some information about the libraries that are being linked in the debug and release make files. 我对makefile不太了解,但是我可以看到有关调试和发布make文件中链接的库的一些信息。

Makefile.debug Makefile.debug

LIBS        =        C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-main-d.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-graphics-d.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-window-d.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-system-d.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-audio-d.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-network-d.a 

Makefile.release Makefile.release

LIBS        =        C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-main.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-graphics.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-window.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-system.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-audio.a C:/Users/Derek/Documents/Development/Projects/Dots-A-Lot/dependencies/SFML-2.1-windows-gcc-4.8-mingw-32bits/lib/libsfml-network.a 

I also have the debug DLLs in the debug output folder (next to the debug executable) and the release DLLs in the release output folder (next to the release executable). 我在debug输出文件夹中(调试可执行文件旁边)还有调试DLL,在release输出文件夹中(release可执行文件旁边)有发布DLL。 The data folder is in both debug and release folders as well so that it has access to the fragment shader file. 数据文件夹也位于debug和release文件夹中,因此它可以访问片段着色器文件。

I was able to solve my problem. 我能够解决我的问题。 I had followed these instructions to build SFML: 我已按照以下说明构建SFML:

http://sfml-dev.org/tutorials/2.1/compile-with-cmake.php http://sfml-dev.org/tutorials/2.1/compile-with-cmake.php

I had downloaded g++ 4.8.1 with mingw and used that to compile SFML. 我已经用mingw下载了g ++ 4.8.1,并用它来编译SFML。 However, when I used the .a/.dll files produced by that build, my release build would crash on that line of code. 但是,当我使用该版本生成的.a / .dll文件时,我的发布版本将在该行代码上崩溃。

Today (10-7-2013) I found these instructions: 今天(2013年10月7日),我找到了以下说明:

https://github.com/LaurentGomila/SFML/wiki/Tutorial%3A-Compile-and-Link-SFML-with-Qt-Creator#step-10 https://github.com/LaurentGomila/SFML/wiki/Tutorial%3A-Compile-and-Link-SFML-with-Qt-Creator#step-10

I ran through those instructions and used the g++ 4.8.0 compiler that came with Qt Creator (instead of the one I had downloaded). 我仔细阅读了这些说明,并使用了Qt Creator随附的g ++ 4.8.0编译器(而不是我下载的编译器)。 Now I am able to run in release mode without crashing. 现在,我可以在发布模式下运行而不会崩溃。

I didn't realize that I was using one version of the compiler to build SFML (g++ 4.8.1) and another to build my application (g++ 4.8.0). 我没有意识到我正在使用一个版本的编译器来构建SFML(g ++ 4.8.1),而使用另一个版本来构建我的应用程序(g ++ 4.8.0)。

Thank you, luiscubal, for pointing me in the right direction by asking me questions about the linker. luiscubal,谢谢您向我询问有关链接器的问题,从而为我指明了正确的方向。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调试运行良好,但不在发布模式下 - Debug runs fine, but not in release mode GCC在调试模式下崩溃,在发布模式下运行正常吗? - GCC crash in debug mode, runs fine in release mode? VS程序在调试而不是发布模式下崩溃? - VS program crashes in debug but not release mode? QT Creator:程序在调试模式下崩溃,但在发布模式和调试模式下工作,带有基于QThread的程序的断点 - QT Creator : Program crashes in debug mode but working in Release mode and in DEBUG Mode with breakpoints for QThread based program 在发布模式下OpenAL Soft崩溃(调试工作正常) - OpenAL Soft crashes in release mode (debug works fine) 在调试模式下访问冲突,但在发布模式下很好 - Access Violation in debug mode, but fine in release mode ActiveX控件在发布模式下崩溃,但在调试模式下不崩溃 - ActiveX control that crashes in release mode but not in debug mode 如果调试运行正常但释放崩溃怎么办 - what to do if debug runs fine, but release crashes 调试模式下未处理的异常,但在发行版中工作正常 - Unhandled exception in debug mode but works fine in release Visual Studio 2008 - vftable指针不正确? 调试模式崩溃,发布很好 - Visual Studio 2008 - vftable pointer incorrect? Debug mode crashes, Release is fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM