From 4f02417442109656263366ffcefd68231a0da7e9 Mon Sep 17 00:00:00 2001 From: ennewalker Date: Tue, 31 Mar 2009 03:08:39 +0000 Subject: [2722438] Fixing crash when viewing shop contents. shop_item* was being blindly casted to monsters*, which didn't play well with a non-existent virtual function table. Fixed by creating a ShopItemEntry and a MonstersMenuEntry class to differentiate the meaning of MenuEntry::data and to avoid crashes in the future by having MenuEntry::get_tiles() be a no-op. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@9572 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/stash.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'crawl-ref/source/stash.cc') diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index cecf818d5c..caa4eed7d5 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -912,6 +912,18 @@ void ShopInfo::describe_shop_item(const shop_item &si) const const_cast(si).item.flags = oldflags; } +class ShopItemEntry : public InvEntry +{ +public: + ShopItemEntry(const ShopInfo::shop_item &it, + const std::string &item_name, + menu_letter hotkey) : InvEntry(it.item) + { + text = item_name; + add_hotkey(hotkey); + } +}; + bool ShopInfo::show_menu(const std::string &place, bool can_travel) const { @@ -937,11 +949,9 @@ bool ShopInfo::show_menu(const std::string &place, { for (int i = 0, count = items.size(); i < count; ++i) { - MenuEntry *me = new MenuEntry(shop_item_name(items[i]), - MEL_ITEM, - 1, - hotkey++); - me->data = const_cast( &items[i] ); + MenuEntry *me = new ShopItemEntry(items[i], + shop_item_name(items[i]), + hotkey++); menu.add_entry(me); } } -- cgit v1.2.3-54-g00ecf