I have encountered a strange behaviour while attempting to write a roguelike. I've made a simple loop printing letters in a filled rectangle shape. With normal (stdscr) window, or newly initialised window from derwin() all works fine. Loop within stdscr/newly initialised window from derwin().
But the issue starts to appear after I return the window pointer from the Game class. Letters seem to be printed without any patttern, and the window looks like it is covered on some parts of it. Loop, when the pointer is returned.
I've tried debugging, but didn't succeed. The cursor is moving, loop is working, letters are printed, but sometimes they get stuck in the astral projection level, and they doesn't show up.
Here is the code: Game.cpp
Game::Game() : m_winMode(WinMode::GameWin) {
[...]
initscr();
wresize(stdscr, WIN_HGHT, WIN_WDTH);
m_gameWin = derwin(stdscr, GAMEWIN_HGHT, GAMEWIN_WDTH, 0, 0);
[...]
}
WINDOW * Game::getWindow(Game::WinMode t_mode) const {
[...]
switch (t_mode) {
case Game::WinMode::GameWin:
return m_gameWin;
break;
[...]
}
pdcurses-test.cpp - this is the main file
#include "stdafx.h"
#include "Game.h"
#include "Map.h"
int main() {
Game game;
game.prepareScreen();
WINDOW * test = game.getWindow(Game::WinMode::GameWin);
wclear(test);
for (int i = 0; i <= 48; i++) {
for (int y = 0; y <= 120; y++) {
mvwaddch(test, i, y, '%');
}
}
wrefresh(test);
Here is the full code: github.com/gebirgestein/pdcurses-test/tree/test/pdcurses-test/pdcurses-test
Thanks in advance.