mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-31 03:39:57 +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)
|
||||
{
|
||||
gameView = new GameView();
|
||||
gameModel = new GameModel();
|
||||
gameModel = new GameModel(gameView); // mvc is a joke
|
||||
gameModel->BuildQuickOptionMenu(this);
|
||||
|
||||
gameView->AttachController(this);
|
||||
gameModel->AddObserver(gameView);
|
||||
gameModel->view = gameView; // mvc is a joke
|
||||
|
||||
gameView->SetDebugHUD(GlobalPrefs::Ref().Get("Renderer.DebugMode", false));
|
||||
|
||||
|
@@ -50,7 +50,7 @@ HistoryEntry::~HistoryEntry()
|
||||
// so the default dtor for ~HistoryEntry cannot be generated.
|
||||
}
|
||||
|
||||
GameModel::GameModel():
|
||||
GameModel::GameModel(GameView *newView):
|
||||
activeMenu(SC_POWDERS),
|
||||
currentBrush(0),
|
||||
currentUser(0, ""),
|
||||
@@ -61,7 +61,8 @@ GameModel::GameModel():
|
||||
colour(255, 0, 0, 255),
|
||||
edgeMode(EDGE_VOID),
|
||||
ambientAirTemp(R_TEMP + 273.15f),
|
||||
decoSpace(DECOSPACE_SRGB)
|
||||
decoSpace(DECOSPACE_SRGB),
|
||||
view(newView)
|
||||
{
|
||||
sim = new Simulation();
|
||||
sim->useLuaCallbacks = true;
|
||||
|
@@ -133,8 +133,10 @@ private:
|
||||
std::optional<int> queuedVote;
|
||||
bool threadedRendering = false;
|
||||
|
||||
GameView *view;
|
||||
|
||||
public:
|
||||
GameModel();
|
||||
GameModel(GameView *newView);
|
||||
~GameModel();
|
||||
|
||||
void Tick();
|
||||
@@ -302,5 +304,8 @@ public:
|
||||
void BeforeSim();
|
||||
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())
|
||||
{
|
||||
pixel colour = gameModel.view->GetPixelUnderMouse();
|
||||
pixel colour = gameModel.GetView()->GetPixelUnderMouse();
|
||||
gameModel.SetColourSelectorColour(RGB<uint8_t>::Unpack(colour).WithAlpha(0xFF));
|
||||
}
|
||||
else
|
||||
|
@@ -831,7 +831,7 @@ static int floodDeco(lua_State *L)
|
||||
|
||||
auto *lsi = GetLSI();
|
||||
// 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 }]);
|
||||
lsi->sim->ApplyDecorationFill(rendererFrame, x, y, r, g, b, a, loc.Red, loc.Green, loc.Blue);
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user