mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 12:02:40 +02:00
Fix nullptr deref when flooding deco
Broken inff4500620e
, where the code that constructs DecorationTools got moved from GameModel::BuildMenus to GameModel::InitTools. BuildMenus used to run fairly late, while InitTools is run fairly early, before GameModel's view member is initialized. This wasn't a problem beforef52e047037
, since which DecorationTools access Renderer through GameView, rather than directly.
This commit is contained in:
@@ -83,12 +83,11 @@ GameController::GameController():
|
|||||||
HasDone(false)
|
HasDone(false)
|
||||||
{
|
{
|
||||||
gameView = new GameView();
|
gameView = new GameView();
|
||||||
gameModel = new GameModel();
|
gameModel = new GameModel(gameView); // mvc is a joke
|
||||||
gameModel->BuildQuickOptionMenu(this);
|
gameModel->BuildQuickOptionMenu(this);
|
||||||
|
|
||||||
gameView->AttachController(this);
|
gameView->AttachController(this);
|
||||||
gameModel->AddObserver(gameView);
|
gameModel->AddObserver(gameView);
|
||||||
gameModel->view = gameView; // mvc is a joke
|
|
||||||
|
|
||||||
gameView->SetDebugHUD(GlobalPrefs::Ref().Get("Renderer.DebugMode", false));
|
gameView->SetDebugHUD(GlobalPrefs::Ref().Get("Renderer.DebugMode", false));
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ HistoryEntry::~HistoryEntry()
|
|||||||
// so the default dtor for ~HistoryEntry cannot be generated.
|
// so the default dtor for ~HistoryEntry cannot be generated.
|
||||||
}
|
}
|
||||||
|
|
||||||
GameModel::GameModel():
|
GameModel::GameModel(GameView *newView):
|
||||||
activeMenu(SC_POWDERS),
|
activeMenu(SC_POWDERS),
|
||||||
currentBrush(0),
|
currentBrush(0),
|
||||||
currentUser(0, ""),
|
currentUser(0, ""),
|
||||||
@@ -61,7 +61,8 @@ GameModel::GameModel():
|
|||||||
colour(255, 0, 0, 255),
|
colour(255, 0, 0, 255),
|
||||||
edgeMode(EDGE_VOID),
|
edgeMode(EDGE_VOID),
|
||||||
ambientAirTemp(R_TEMP + 273.15f),
|
ambientAirTemp(R_TEMP + 273.15f),
|
||||||
decoSpace(DECOSPACE_SRGB)
|
decoSpace(DECOSPACE_SRGB),
|
||||||
|
view(newView)
|
||||||
{
|
{
|
||||||
sim = new Simulation();
|
sim = new Simulation();
|
||||||
sim->useLuaCallbacks = true;
|
sim->useLuaCallbacks = true;
|
||||||
|
@@ -133,8 +133,10 @@ private:
|
|||||||
std::optional<int> queuedVote;
|
std::optional<int> queuedVote;
|
||||||
bool threadedRendering = false;
|
bool threadedRendering = false;
|
||||||
|
|
||||||
|
GameView *view;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameModel();
|
GameModel(GameView *newView);
|
||||||
~GameModel();
|
~GameModel();
|
||||||
|
|
||||||
void Tick();
|
void Tick();
|
||||||
@@ -302,5 +304,8 @@ public:
|
|||||||
void BeforeSim();
|
void BeforeSim();
|
||||||
void AfterSim();
|
void AfterSim();
|
||||||
|
|
||||||
GameView *view = nullptr;
|
GameView *GetView() const
|
||||||
|
{
|
||||||
|
return view;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@@ -23,7 +23,7 @@ void SampleTool::Draw(Simulation * sim, Brush const &brush, ui::Point position)
|
|||||||
{
|
{
|
||||||
if(gameModel.GetColourSelectorVisibility())
|
if(gameModel.GetColourSelectorVisibility())
|
||||||
{
|
{
|
||||||
pixel colour = gameModel.view->GetPixelUnderMouse();
|
pixel colour = gameModel.GetView()->GetPixelUnderMouse();
|
||||||
gameModel.SetColourSelectorColour(RGB<uint8_t>::Unpack(colour).WithAlpha(0xFF));
|
gameModel.SetColourSelectorColour(RGB<uint8_t>::Unpack(colour).WithAlpha(0xFF));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -831,7 +831,7 @@ static int floodDeco(lua_State *L)
|
|||||||
|
|
||||||
auto *lsi = GetLSI();
|
auto *lsi = GetLSI();
|
||||||
// hilariously broken, intersects with console and all Lua graphics
|
// hilariously broken, intersects with console and all Lua graphics
|
||||||
auto &rendererFrame = lsi->gameModel->view->GetRendererFrame();
|
auto &rendererFrame = lsi->gameModel->GetView()->GetRendererFrame();
|
||||||
auto loc = RGB<uint8_t>::Unpack(rendererFrame[{ x, y }]);
|
auto loc = RGB<uint8_t>::Unpack(rendererFrame[{ x, y }]);
|
||||||
lsi->sim->ApplyDecorationFill(rendererFrame, x, y, r, g, b, a, loc.Red, loc.Green, loc.Blue);
|
lsi->sim->ApplyDecorationFill(rendererFrame, x, y, r, g, b, a, loc.Red, loc.Green, loc.Blue);
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user