Code Monkey home page Code Monkey logo

miniengine's People

Contributors

kiritow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

asdlei99

miniengine's Issues

SDL_Renderer改变引起的SDL_Texture失效问题

测试代码如下

#include <iostream>
using namespace std;

#include "MiniEngine.h"
#include "MiniEngine_Widget.h"
using namespace MiniEngine;

int AppMain()
{
    Window wnd("Title",1280,768);
    Renderer rnd=wnd.getRenderer();
    Texture t=rnd.loadTexture("1.png");
    Texture b=rnd.loadTexture("2.png");
    rnd.clear();
    rnd.copyFullFill(t);
    rnd.update();
    while(1)
    {
        SDL_Event e;
        SDL_WaitEvent(&e);
        if(e.type==SDL_MOUSEBUTTONDOWN) break;
    }
    cout<<"Changed"<<endl;
    wnd.setRenderer(RendererType::Accelerated);
    Renderer nrnd=wnd.getRenderer();
    cout<<rnd.isReady()<<" "<<nrnd.isReady()<<endl;

    nrnd.clear();
    nrnd.update();
    ErrorViewer ss;
    ss.fetch();
    cout<<ss.what()<<endl;
    while(1)
    {
        SDL_Event e;
        SDL_WaitEvent(&e);
        if(e.type==SDL_MOUSEBUTTONDOWN) break;
    }
    nrnd.clear();
    nrnd.copyFullFill(b);
    nrnd.update();
    ss.fetch();
    cout<<ss.what()<<endl;
    cout<<"Printed"<<endl;
    while(1)
    {
        SDL_Event e;
        SDL_WaitEvent(&e);
        if(e.type==SDL_MOUSEBUTTONDOWN) break;
    }

    return 0;
}

根据当前情况,nrnd的建立会导致rnd的失效,此时rnd渲染的t和b都处于无效状态(Invalid Texture).
解决这个问题可以将Texture中的指针改为weak_ptr,并将真正的Texture放入Window类中. 但是这样的话又不能在Texture超出作用域的时候自动释放(因为都保存在Window里了),这样很有可能引起内存暴涨...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.