mirror of
https://github.com/holub/mame
synced 2025-04-20 23:42:22 +03:00
memory_view: fix possible nullptr crash, add exists() getter
This commit is contained in:
parent
76323a8fd1
commit
1949b85c81
@ -2645,13 +2645,13 @@ public:
|
||||
|
||||
void select(int entry);
|
||||
void disable();
|
||||
bool exists() const { return m_config != nullptr; }
|
||||
|
||||
std::optional<int> entry() const { return m_cur_id == -1 ? std::optional<int>() : m_cur_slot; }
|
||||
|
||||
const std::string &name() const { return m_name; }
|
||||
|
||||
private:
|
||||
|
||||
device_t & m_device;
|
||||
std::string m_name;
|
||||
std::map<int, int> m_entry_mapping;
|
||||
@ -2671,6 +2671,7 @@ private:
|
||||
void make_subdispatch(std::string context);
|
||||
int id_to_slot(int id) const;
|
||||
void register_state();
|
||||
void refresh_id();
|
||||
};
|
||||
|
||||
|
||||
|
@ -505,18 +505,25 @@ void memory_view::register_state()
|
||||
{
|
||||
m_device.machine().save().save_item(&m_device, "view", m_device.subtag(m_name).c_str(), 0, NAME(m_cur_slot));
|
||||
m_device.machine().save().save_item(&m_device, "view", m_device.subtag(m_name).c_str(), 0, NAME(m_cur_id));
|
||||
m_device.machine().save().register_postload(save_prepost_delegate(NAME([this]() { m_handler_read->select_a(m_cur_id); m_handler_write->select_a(m_cur_id); })));
|
||||
m_device.machine().save().register_postload(save_prepost_delegate(FUNC(memory_view::refresh_id), this));
|
||||
}
|
||||
|
||||
void memory_view::refresh_id()
|
||||
{
|
||||
if (m_handler_read) {
|
||||
m_handler_read->select_a(m_cur_id);
|
||||
m_handler_write->select_a(m_cur_id);
|
||||
}
|
||||
|
||||
if (m_space)
|
||||
m_space->invalidate_caches(read_or_write::READWRITE);
|
||||
}
|
||||
|
||||
void memory_view::disable()
|
||||
{
|
||||
m_cur_slot = -1;
|
||||
m_cur_id = -1;
|
||||
m_handler_read->select_a(-1);
|
||||
m_handler_write->select_a(-1);
|
||||
|
||||
if(m_space)
|
||||
m_space->invalidate_caches(read_or_write::READWRITE);
|
||||
refresh_id();
|
||||
}
|
||||
|
||||
void memory_view::select(int slot)
|
||||
@ -527,11 +534,7 @@ void memory_view::select(int slot)
|
||||
|
||||
m_cur_slot = slot;
|
||||
m_cur_id = i->second;
|
||||
m_handler_read->select_a(m_cur_id);
|
||||
m_handler_write->select_a(m_cur_id);
|
||||
|
||||
if(m_space)
|
||||
m_space->invalidate_caches(read_or_write::READWRITE);
|
||||
refresh_id();
|
||||
}
|
||||
|
||||
int memory_view::id_to_slot(int id) const
|
||||
|
Loading…
Reference in New Issue
Block a user