1
General / Heap Corruption?
« on: June 24, 2011, 12:08:25 am »
So of course I rewrite it and it starts working fine.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#define _WIDTH_ 32
#define _HEIGHT_ 64
#define _ZOOM_ 20
int main()
{
sf::RenderWindow App(sf::VideoMode(_WIDTH_*_ZOOM_, _HEIGHT_*_ZOOM_), "Test");
sf::View View(sf::FloatRect(0, 0, _WIDTH_, _HEIGHT_));
View.Zoom(_ZOOM_);
sf::Image Image(_WIDTH_, _HEIGHT_, sf::Color(0, 0, 0));
sf::Sprite Sprite;
sf::Uint8 *Display = new sf::Uint8[_WIDTH_ * _HEIGHT_ * 4];
while(App.IsOpened())
{
sf::Event e;
while(App.GetEvent(e))
{
if(e.Type == sf::Event::Closed)
App.Close();
}
for(int i = 0; i < _WIDTH_; i++)
for(int j = 0; j < _HEIGHT_; j++)
{
Display[(j+i*_WIDTH_)*4] = i*j % 255; // R
Display[(j+i*_WIDTH_)*4+1] = i*j % 255; // G
Display[(j+i*_WIDTH_)*4+2] = i*j % 255; // B
Display[(j+i*_WIDTH_)*4+3] = 255; // A
}
App.Clear();
Image.LoadFromPixels(_WIDTH_, _HEIGHT_, Display);
Sprite.SetImage(Image);
App.Draw(Sprite);
App.SetView(View);
App.Display();
}
delete [] Display;
return 0;
}
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#define _WIDTH_ 32
#define _HEIGHT_ 64
#define _ZOOM_ 20
int main()
{
sf::RenderWindow App(sf::VideoMode(_WIDTH_*_ZOOM_, _HEIGHT_*_ZOOM_), "Test");
sf::View View(sf::FloatRect(0, 0, _WIDTH_, _HEIGHT_));
View.Zoom(_ZOOM_);
sf::Image Image(_WIDTH_, _HEIGHT_, sf::Color(0, 0, 0));
sf::Sprite Sprite;
sf::Uint8 *Display = new sf::Uint8[_WIDTH_ + _HEIGHT_ * 4];
while(App.IsOpened())
{
sf::Event e;
while(App.GetEvent(e))
{
if(e.Type == sf::Event::Closed)
App.Close();
for(int i = 0; i < _WIDTH_; i++)
for(int j = 0; j < _HEIGHT_; j++)
{
Display[(j+i*_WIDTH_)*4] = i*j % 255; // R
Display[(j+i*_WIDTH_+1)*4] = i*j % 255; // G
Display[(j+i*_WIDTH_+2)*4] = i*j % 255; // B
Display[(j+i*_WIDTH_+3)*4] = 255; // A
}
App.Clear();
Image.LoadFromPixels(_WIDTH_, _HEIGHT_, Display);
Sprite.SetImage(Image);
App.Draw(Sprite);
App.SetView(View);
App.Display();
}
}
delete [] Display;
return 0;
}