Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move file-static RenderWindow and RenderTexture instances inside functions to fix GL race condition on startup #677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/dialogxml/dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ using namespace std;
using namespace ticpp;

// TODO: Would be nice if I could avoid depending on mainPtr
extern sf::RenderWindow mainPtr;

extern sf::Texture bg_gworld;
const short cDialog::BG_DARK = 5, cDialog::BG_LIGHT = 16;
short cDialog::defaultBackground = cDialog::BG_DARK;
cDialog* cDialog::topWindow = nullptr;
Expand Down Expand Up @@ -496,7 +494,7 @@ bool cDialog::sendInput(cKey key) {
void cDialog::run(std::function<void(cDialog&)> onopen){
cDialog* formerTop = topWindow;
// TODO: The introduction of the static topWindow means I may be able to use this instead of parent->win; do I still need parent?
sf::RenderWindow* parentWin = &(parent ? parent->win : mainPtr);
sf::RenderWindow* parentWin = &(parent ? parent->win : mainPtr());
auto parentPos = parentWin->getPosition();
auto parentSz = parentWin->getSize();
cursor_type former_curs = Cursor::current;
Expand Down Expand Up @@ -530,7 +528,7 @@ void cDialog::run(std::function<void(cDialog&)> onopen){
winLastY = parentPos.y + (int(parentSz.y) - winRect.height()) / 2;
win.setPosition({winLastX, winLastY});
draw();
makeFrontWindow(parent ? parent-> win : mainPtr);
makeFrontWindow(parent ? parent-> win : mainPtr());
makeFrontWindow(win);
// This is a loose modal session, as it doesn't prevent you from clicking away,
// but it does prevent editing other dialogs, and it also keeps this window on top
Expand Down
2 changes: 0 additions & 2 deletions src/dialogxml/widgets/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include "fileio/resmgr/res_image.hpp"

extern sf::Texture bg_gworld;

cButton::cButton(iComponent& parent) :
cControl(CTRL_BTN,parent),
wrapLabel(false),
Expand Down
2 changes: 0 additions & 2 deletions src/dialogxml/widgets/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "dialogxml/dialogs/dialog.hpp"
#include <numeric>

extern sf::Texture bg_gworld;

bool cTextMsg::manageFormat(eFormat prop, bool set, boost::any* val) {
switch(prop) {
case TXT_FRAME:
Expand Down
1 change: 0 additions & 1 deletion src/dialogxml/widgets/pict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "dialogxml/dialogs/strdlog.hpp"
#include "fileio/resmgr/res_image.hpp"

extern sf::Texture bg_gworld;
extern cCustomGraphics spec_scen_g;
const pic_num_t cPict::BLANK = -1;

Expand Down
28 changes: 13 additions & 15 deletions src/game/boe.actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ extern bool party_in_memory;
extern sf::View mainView;

// game info globals
extern sf::RenderWindow mainPtr;
extern short which_item_page[6];
extern short store_spell_target,pc_casting;
extern eSpell store_mage, store_priest;
Expand All @@ -107,7 +106,6 @@ extern short combat_active_pc;
extern eStatMode stat_screen_mode;

extern bool map_visible;
extern sf::RenderWindow mini_map;

extern std::shared_ptr<cScrollbar> text_sbar,item_sbar,shop_sbar;
extern short shop_identify_cost, shop_recharge_amount;
Expand Down Expand Up @@ -476,7 +474,7 @@ void handle_rest(bool& need_redraw, bool& need_reprint) {
i = 200;
add_string_to_buf(" Monsters nearby.");
}
while(pollEvent(mainPtr, dummy_evt));
while(pollEvent(mainPtr(), dummy_evt));
redraw_screen(REFRESH_NONE);
i++;
}
Expand Down Expand Up @@ -1128,7 +1126,7 @@ static void handle_town_wait(bool& need_redraw, bool& need_reprint) {
i = 200;
add_string_to_buf(" Monster sighted!");
}
while(pollEvent(mainPtr, dummy_evt));
while(pollEvent(mainPtr(), dummy_evt));
redraw_screen(REFRESH_NONE);
}
put_pc_screen();
Expand Down Expand Up @@ -1392,7 +1390,7 @@ bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {
location point_in_area;

location the_point(event.mouseButton.x, event.mouseButton.y);
the_point = mainPtr.mapPixelToCoords(the_point, mainView);
the_point = mainPtr().mapPixelToCoords(the_point, mainView);
end_scenario = false;

// MARK: First, figure out where party is
Expand Down Expand Up @@ -1420,7 +1418,7 @@ bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {

// Otherwise they're in a terrain view mode
location cur_loc = is_out() ? univ.party.out_loc : center;
auto button_hit = UI::toolbar.button_hit(mainPtr, the_point, fps_limiter);
auto button_hit = UI::toolbar.button_hit(mainPtr(), the_point, fps_limiter);

// MARK: Then, handle a button being hit.
switch(button_hit) {
Expand Down Expand Up @@ -2332,9 +2330,9 @@ void close_map(bool record) {
if(record && recording){
record_action("close_map", "");
}
mini_map.setVisible(false);
mini_map().setVisible(false);
map_visible = false;
mainPtr.setActive();
mainPtr().setActive();
}

void cancel_item_target(bool& did_something, bool& need_redraw, bool& need_reprint) {
Expand Down Expand Up @@ -2647,7 +2645,7 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
pass_point = talk_words[i].rect.topLeft();
pass_point.x += talk_area_rect.left+9;
pass_point.y += talk_area_rect.top+9;
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
pass_point = mainPtr().mapCoordsToPixel(pass_point, mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
are_done = handle_action(pass_event, fps_limiter);
Expand All @@ -2664,7 +2662,7 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
// related to talk_area_rect
pass_point.x += talk_area_rect.left+9;
pass_point.y += talk_area_rect.top+9;
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
pass_point = mainPtr().mapCoordsToPixel(pass_point, mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
are_done = handle_action(pass_event, fps_limiter);
Expand All @@ -2678,7 +2676,7 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
else {
if(!handle_screen_shift(screen_shift_delta[i], need_redraw)){
// Directional keys simulate directional click
pass_point = mainPtr.mapCoordsToPixel(terrain_click[i], mainView);
pass_point = mainPtr().mapCoordsToPixel(terrain_click[i], mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
are_done = handle_action(pass_event, fps_limiter);
Expand Down Expand Up @@ -2884,11 +2882,11 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
bool handle_scroll(const sf::Event& event) {
rectangle world_screen = win_to_rects[WINRECT_TERVIEW];
world_screen.inset(13, 13);
fill_rect(mainPtr, world_screen, sf::Color::Magenta);
fill_rect(mainPtr(), world_screen, sf::Color::Magenta);

// TODO: centralize this translation somewhere
location pos(event.mouseWheel.x, event.mouseWheel.y);
pos = mainPtr.mapPixelToCoords(pos, mainView);
pos = mainPtr().mapPixelToCoords(pos, mainView);

int amount = event.mouseWheel.delta;
if(scrollableModes.count(overall_mode) && pos.in(world_screen)) {
Expand Down Expand Up @@ -2937,7 +2935,7 @@ void post_load() {
set_stat_window(ITEM_WIN_PC1);
put_pc_screen();
draw_terrain();
UI::toolbar.draw(mainPtr);
UI::toolbar.draw(mainPtr());
draw_text_bar();

print_buf();
Expand Down Expand Up @@ -3981,7 +3979,7 @@ bool check_for_interrupt(std::string confirm_dialog){
pop_next_action();
interrupt = true;
}
else if(pollEvent(mainPtr, evt) && evt.type == sf::Event::KeyPressed) {
else if(pollEvent(mainPtr(), evt) && evt.type == sf::Event::KeyPressed) {
// TODO: I wonder if there are other events we should handle here? Resize maybe?
#ifdef __APPLE__
if(evt.key.code == kb::Period && evt.key.system)
Expand Down
7 changes: 3 additions & 4 deletions src/game/boe.combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ extern location center;
extern short combat_active_pc;
extern bool monsters_going,spell_forced;
extern bool flushingInput;
extern sf::RenderWindow mainPtr;
extern eSpell store_mage, store_priest;
extern short store_mage_lev, store_priest_lev,store_item_spell_level;
extern short store_spell_target,pc_casting,current_spell_range;
Expand Down Expand Up @@ -267,7 +266,7 @@ void start_outdoor_combat(cOutdoors::cWandering encounter,location where,short n
print_buf();
play_sound(23);

mainPtr.setActive();
mainPtr().setActive();
which_combat_type = 0;
overall_mode = MODE_COMBAT;

Expand Down Expand Up @@ -357,7 +356,7 @@ void start_outdoor_combat(cOutdoors::cWandering encounter,location where,short n
set_pc_moves();
pick_next_pc();
center = univ.current_pc().combat_pos;
UI::toolbar.draw(mainPtr);
UI::toolbar.draw(mainPtr());
put_pc_screen();
set_stat_window_for_pc(univ.cur_pc);

Expand Down Expand Up @@ -4715,7 +4714,7 @@ void end_combat() {
if(univ.current_pc().main_status != eMainStatus::ALIVE)
univ.cur_pc = first_active_pc();
put_item_screen(stat_window);
UI::toolbar.draw(mainPtr);
UI::toolbar.draw(mainPtr());
}


Expand Down
12 changes: 4 additions & 8 deletions src/game/boe.dlgutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
extern eItemWinMode stat_window;
extern eGameMode overall_mode;
extern bool changed_display_mode;
extern sf::RenderWindow mainPtr;
extern rectangle d_rects[80];
extern short d_rect_index[80];
extern eStatMode stat_screen_mode;
Expand All @@ -55,9 +54,7 @@ extern location center;
extern std::shared_ptr<cScrollbar> text_sbar,item_sbar,shop_sbar;
extern std::shared_ptr<cButton> done_btn, help_btn;
extern bool map_visible;
extern sf::RenderWindow mini_map;
extern cUniverse univ;
extern sf::Texture pc_gworld;
extern std::map<eSkill,short> skill_max;
extern void give_help_and_record(short help1, short help2, bool help_forced = false);

Expand All @@ -70,7 +67,6 @@ extern bool party_in_memory;
eGameMode store_pre_talk_mode;
short store_personality,store_personality_graphic,shop_identify_cost,shop_recharge_amount,shop_recharge_limit;
std::string save_talk_str1, save_talk_str2;
sf::RenderTexture talk_gworld;
bool talk_end_forced;
rectangle talk_area_rect = {7,19,422,298}, word_place_rect = {44,7,372,257},talk_help_rect = {7,268,23,286};
std::string title_string;
Expand Down Expand Up @@ -140,7 +136,7 @@ bool start_shop_mode(short which,short cost_adj,std::string store_name, bool can
}

area_rect = talk_area_rect;
talk_gworld.create(area_rect.width(), area_rect.height());
talk_gworld().create(area_rect.width(), area_rect.height());

store_pre_shop_mode = overall_mode;
overall_mode = MODE_SHOPPING;
Expand Down Expand Up @@ -262,7 +258,7 @@ bool handle_shop_event(location p, cFramerateLimiter& fps_limiter) {
return true;
}
}
return p.in(rectangle(talk_gworld));
return p.in(rectangle(talk_gworld()));
}

void handle_sale(int i) {
Expand Down Expand Up @@ -637,7 +633,7 @@ void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short st
store_m_num = m_num;
store_talk_face_pic = store_face_pic; ////
area_rect = talk_area_rect;
talk_gworld.create(area_rect.width(), area_rect.height());
talk_gworld().create(area_rect.width(), area_rect.height());
help_btn->show();

// This would be the place to show the text box, if I add it.
Expand Down Expand Up @@ -1157,7 +1153,7 @@ bool handle_talk_event(location p, cFramerateLimiter& fps_limiter) {
break;
}
handle_talk_node(which_talk_entry);
return clicked_word || p.in(rectangle(talk_gworld));
return clicked_word || p.in(rectangle(talk_gworld()));
}

//town_num; // Will be 0 - 200 for town, 200 - 290 for outdoors
Expand Down
2 changes: 0 additions & 2 deletions src/game/boe.fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ extern eGameMode overall_mode;
extern bool party_in_memory;
extern location center;
extern long register_flag;
extern sf::RenderWindow mainPtr;
extern bool map_visible;
extern sf::RenderWindow mini_map;
extern short which_combat_type;
extern short cur_town_talk_loaded;
extern cUniverse univ;
Expand Down
Loading