Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TopWindow&PopUp, TrayIcon » TopWindow when Close override show exception unduly
Re: TopWindow when Close override show exception unduly [message #56193 is a reply to message #56182] Sun, 07 February 2021 10:31 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14265
Registered: November 2005
Ultimate Member
Oblivion wrote on Thu, 04 February 2021 16:21
Hello BetoValle,

    void Close() override {
        delete this; // error show heap is corrupted !!!!
    }
 


I don't think there is any bug in U++. You are trying to delete an object within the same object. That call to TopWindow::Close() will return to its caller, which is the TopWindow itself, and it will be a freed memory address. So you get heap corruption. Never do that. Smile


That is actually OK if it is the last thing you do to the object, regardless it being in the object's method. Both by C++ standard and U++ Close. Well, should probably be documented.. Similar approach is used here: https://www.ultimatepp.org/examples$UWord$en-us.html

In fact, "delete this" is sort of the only "delete" that is allowed in U++ Smile

Quote:

Not to mention the SMain instance (se) is allocated on stack. You don't need to delete it anyway.


That is the real problem.

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to remove the button [X] that closes the window?
Next Topic: same layout with different dimensions
Goto Forum:
  


Current Time: Mon Jul 07 18:35:35 CEST 2025

Total time taken to generate the page: 0.03596 seconds