【问题标题】:Crashes with some types sfml on androidAndroid 上某些类型的 sfml 崩溃
【发布时间】:2022-12-09 17:05:01
【问题描述】:

在 android 上编程,更具体地说cxx机器人c4droid.在这两个程序中,我在创建 sf::Texturesf::RenderWindow 类型的变量而不是进入 main() 时遇到崩溃,但 visual studio 没有问题

基本示例:

#include <SFML/Graphics.hpp>
using namespace sf;
RenderWindow window(VideoMode(1080, 1920), "sfml"); //crashing

int main()
{
while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
                window.close();
        }

window.clear();
window.display();
    }
return 0;
}

你能告诉我如何在 main() 之前创建它的变量,或者建议另一个没有问题的 android 编译器吗?

【问题讨论】:

    标签: android c++ compiler-errors sfml


    【解决方案1】:

    要使用RenderWindowTexture,我猜想使用引用&类型名称在函数的变量中。

    #include <SFML/Graphics.hpp>
    using namespace sf;
    
    Sprite sprite;
    
    void WinUse(RenderWindow &window)
    {
        window.draw(sprite);
    }
    
    int main()
    {
        RenderWindow window(VideoMode(1080, 1920), "sfml");
        
        
        Texture texture;
        texture.loadFromFile("any.png");
        sprite.setTexture(texture);
        
        
    while (window.isOpen())
        {
            Event event;
            while (window.pollEvent(event))
            {
                if (event.type == Event::Closed)
                    window.close();
            }
    
    window.clear();
    WinUse(window);
    window.display();
        }
    return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      • 2016-05-22
      相关资源
      最近更新 更多